Skip to content

Commit

Permalink
circular reference test is also done with tagged union
Browse files Browse the repository at this point in the history
Unfortunately it does not work...
  • Loading branch information
matmel committed Jan 6, 2023
1 parent 71abdc4 commit aebf0d3
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/strategies/test_include_subclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ def conv_w_subclasses(request):
c = Converter()
if request.param == "with-subclasses":
include_subclasses(Parent, c)
include_subclasses(CircularA, c)
elif request.param == "with-subclasses-and-tagged-union":
union_strategy = partial(configure_tagged_union, tag_name="type_name")
include_subclasses(Parent, c, union_strategy=union_strategy)
include_subclasses(CircularA, c, union_strategy=union_strategy)

return c, request.param

Expand Down Expand Up @@ -185,13 +187,28 @@ def test_structure_as_union():
assert res == [Child1(1, 2)]


def test_circular_reference():
c = Converter()
include_subclasses(CircularA, c)
def test_circular_reference(conv_w_subclasses):
c, included_subclasses_param = conv_w_subclasses

struct = CircularB(a=1, other=[CircularB(a=2, other=[], b=3)], b=4)
unstruct = dict(a=1, other=[dict(a=2, other=[], b=3)], b=4)
unstruct = dict(
a=1,
other=[dict(a=2, other=[], b=3, type_name="CircularB")],
b=4,
type_name="CircularB",
)

if included_subclasses_param != "with-subclasses-and-tagged-union":
unstruct = _remove_type_name(unstruct)

if included_subclasses_param == "wo-subclasses":
# We already now that it will fail
return

res = c.unstructure(struct)
if "wo-subclasses" or "tagged-union" in included_subclasses_param:
# TODO: tagged-union should work here, but it does not yet.
pytest.xfail("Cannot succeed if include_subclasses strategy is not used")
assert res == unstruct

res = c.unstructure(struct, CircularA)
Expand Down

0 comments on commit aebf0d3

Please sign in to comment.