Skip to content

Commit

Permalink
TST: test type hinting on Union types constructed with |
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcar17 committed May 2, 2024
1 parent 4d30ae5 commit 962e141
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tests/test_app/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ def test_get_constraint_names():

def test_get_constraint_names_builtins():
"""handles built-in types"""
expected = {"str", "bytes"}

got = get_constraint_names(Union[str, bytes])
assert got == {"str", "bytes"}
assert got == expected

if sys.version_info.minor > 9:
got = get_constraint_names(str | bytes)
assert got == expected


def test_get_constraint_names_serilisable():
Expand All @@ -63,16 +68,27 @@ def test_get_constraint_names_identifiertype():

def test_get_constraint_names_mixed_serilisable_identifiertype():
"""SerialisableType does not define any compatible types"""
expected = {"SerialisableType", "IdentifierType", "Alignment", "ArrayAlignment"}

got = get_constraint_names(Union[SerialisableType, IdentifierType, AlignedSeqsType])
assert got == {"SerialisableType", "IdentifierType", "Alignment", "ArrayAlignment"}
assert got == expected

if sys.version_info.minor > 9:
got = get_constraint_names(SerialisableType | IdentifierType | AlignedSeqsType)
assert got == expected


def test_hints_resolved_from_str():
got = get_constraint_names("DnaSequence")
assert got == {"DnaSequence"}

expected = {"SerialisableType", "DnaSequence"}
got = get_constraint_names(Union[SerialisableType, "DnaSequence"])
assert got == {"SerialisableType", "DnaSequence"}
assert got == expected

if sys.version_info.minor > 9:
got = get_constraint_names(SerialisableType | "DnaSequence")
assert got == expected


@pytest.mark.parametrize("container", (List, Tuple, Set))
Expand Down

0 comments on commit 962e141

Please sign in to comment.