Skip to content

Commit

Permalink
Add test for deserialization direction
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaps0dy committed May 10, 2024
1 parent c6be3b0 commit 0d84ae9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions databind/src/databind/json/tests/converters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,10 +728,16 @@ class InheritGeneric(GenericClass): # type: ignore[type-arg]
b_field: str


def test_serialize_generic_dataclass() -> None:
@pytest.mark.parametrize("direction", (Direction.SERIALIZE, Direction.DESERIALIZE))
def test_convert_generic_dataclass(direction: Direction) -> None:
"""Regression test for #66: dataclasses inheriting from Generic with an uninstantiated TypeVar don't get their
parents' fields.
"""
obj = InheritGeneric(2, "hi")
mapper = make_mapper([SchemaConverter(), PlainDatatypeConverter()])
assert mapper.serialize(obj, InheritGeneric) == {"a_field": obj.a_field, "b_field": obj.b_field}

if direction == Direction.SERIALIZE:
obj = InheritGeneric(2, "hi")
assert mapper.convert(direction, obj, InheritGeneric) == {"a_field": obj.a_field, "b_field": obj.b_field}
else:
obj = InheritGeneric(4, "something")
assert mapper.convert(direction, {"a_field": obj.a_field, "b_field": obj.b_field}, InheritGeneric) == obj

0 comments on commit 0d84ae9

Please sign in to comment.