Skip to content

Commit 1a8f5c6

Browse files
committed
Add test to repro #322
Signed-off-by: Fabrice Normandin <[email protected]>
1 parent 5fb5676 commit 1a8f5c6

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

test/test_literal.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import enum
22
import sys
33
from dataclasses import dataclass
4-
from typing import Any, List, NamedTuple, Optional
4+
from typing import Any, List, Literal, NamedTuple, Optional, Union
55

66
import pytest
7-
from typing_extensions import Literal
87

98
from .testutils import (
109
TestSetup,
@@ -118,3 +117,22 @@ def test_reproduce_issue_259_parsing_literal_py39():
118117
"argument --param: invalid typing.Literal['bar', 'biz'] value: 'biz'"
119118
):
120119
assert SomeFoo.setup("").param == "biz"
120+
121+
122+
@dataclass
123+
class Foo:
124+
bar: Union[Literal["a"], int] = "a"
125+
126+
127+
def test_issue_322():
128+
"""Test for https://github.com/lebrice/SimpleParsing/issues/322."""
129+
from simple_parsing import parse
130+
131+
assert parse(Foo, args="") == Foo()
132+
assert parse(Foo, args="--bar=a") == Foo(bar="a")
133+
with raises_invalid_choice():
134+
assert parse(Foo, args="--bar=b")
135+
136+
assert parse(Foo, args="--bar=123") == Foo(bar=123)
137+
# TODO: What about this again?
138+
assert parse(Foo, args="--bar=1.23") == Foo(bar=1)

0 commit comments

Comments
 (0)