Skip to content

Commit aebf0d3

Browse files
committed
circular reference test is also done with tagged union
Unfortunately it does not work...
1 parent 71abdc4 commit aebf0d3

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

tests/strategies/test_include_subclasses.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ def conv_w_subclasses(request):
135135
c = Converter()
136136
if request.param == "with-subclasses":
137137
include_subclasses(Parent, c)
138+
include_subclasses(CircularA, c)
138139
elif request.param == "with-subclasses-and-tagged-union":
139140
union_strategy = partial(configure_tagged_union, tag_name="type_name")
140141
include_subclasses(Parent, c, union_strategy=union_strategy)
142+
include_subclasses(CircularA, c, union_strategy=union_strategy)
141143

142144
return c, request.param
143145

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

187189

188-
def test_circular_reference():
189-
c = Converter()
190-
include_subclasses(CircularA, c)
190+
def test_circular_reference(conv_w_subclasses):
191+
c, included_subclasses_param = conv_w_subclasses
192+
191193
struct = CircularB(a=1, other=[CircularB(a=2, other=[], b=3)], b=4)
192-
unstruct = dict(a=1, other=[dict(a=2, other=[], b=3)], b=4)
194+
unstruct = dict(
195+
a=1,
196+
other=[dict(a=2, other=[], b=3, type_name="CircularB")],
197+
b=4,
198+
type_name="CircularB",
199+
)
200+
201+
if included_subclasses_param != "with-subclasses-and-tagged-union":
202+
unstruct = _remove_type_name(unstruct)
203+
204+
if included_subclasses_param == "wo-subclasses":
205+
# We already now that it will fail
206+
return
193207

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

197214
res = c.unstructure(struct, CircularA)

0 commit comments

Comments
 (0)