Skip to content

Commit

Permalink
Add test to repro #322
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Normandin <[email protected]>
  • Loading branch information
lebrice committed Sep 5, 2024
1 parent 5fb5676 commit 1a8f5c6
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions test/test_literal.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import enum
import sys
from dataclasses import dataclass
from typing import Any, List, NamedTuple, Optional
from typing import Any, List, Literal, NamedTuple, Optional, Union

import pytest
from typing_extensions import Literal

from .testutils import (
TestSetup,
Expand Down Expand Up @@ -118,3 +117,22 @@ def test_reproduce_issue_259_parsing_literal_py39():
"argument --param: invalid typing.Literal['bar', 'biz'] value: 'biz'"
):
assert SomeFoo.setup("").param == "biz"


@dataclass
class Foo:
bar: Union[Literal["a"], int] = "a"


def test_issue_322():
"""Test for https://github.com/lebrice/SimpleParsing/issues/322."""
from simple_parsing import parse

assert parse(Foo, args="") == Foo()
assert parse(Foo, args="--bar=a") == Foo(bar="a")
with raises_invalid_choice():
assert parse(Foo, args="--bar=b")

assert parse(Foo, args="--bar=123") == Foo(bar=123)
# TODO: What about this again?
assert parse(Foo, args="--bar=1.23") == Foo(bar=1)

0 comments on commit 1a8f5c6

Please sign in to comment.