Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dkraczkowski committed May 28, 2024
1 parent 679be73 commit c0b262e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,21 @@ class Pet:


def test_can_decode_new_optional_type_notation() -> None:
# given
@decodable
class Tag:
value: int | None

def __init__(self, value: str):
def __init__(self, value: int | None):
self.value = value

tag = decode({}, Tag)
value = {}
alt_value = {"value": 11}

assert tag.value is None
# when
result = decode(value, Tag)
alt_result = decode(alt_value, Tag)

# then
assert result.value is None
assert alt_result.value == 11
21 changes: 21 additions & 0 deletions tests/test_encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,24 @@ def test_can_encode_regex_with_flags_into_string() -> None:

# then
assert result == f"/{pattern_str}/imsx"


def test_can_encode_new_optional_type_notation() -> None:
# given
@encodable
class Tag:
value: int | None

def __init__(self, value: int | None):
self.value = value

tag = Tag(None)
alt_tag = Tag(11)

# when
result = encode(tag)
alt_result = encode(alt_tag)

# then
assert result == {"value": None}
assert alt_result == {"value": 11}

0 comments on commit c0b262e

Please sign in to comment.