Skip to content

Commit 66eda5b

Browse files
committed
Small test refactor
1 parent f553389 commit 66eda5b

3 files changed

Lines changed: 95 additions & 56 deletions

File tree

tests/test_baseconverter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_simple_roundtrip(cls_and_vals, strat):
2828

2929

3030
@given(
31-
simple_typed_attrs(defaults=True, newtypes=False, allow_nan=False),
31+
simple_typed_attrs(defaults="always", newtypes=False, allow_nan=False),
3232
unstructure_strats,
3333
)
3434
def test_simple_roundtrip_defaults(attr_and_strat, strat):
@@ -73,8 +73,8 @@ def test_nested_roundtrip_tuple(cls_and_vals):
7373

7474
@settings(suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow])
7575
@given(
76-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False),
77-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False),
76+
simple_typed_classes(defaults="never", newtypes=False, allow_nan=False),
77+
simple_typed_classes(defaults="never", newtypes=False, allow_nan=False),
7878
unstructure_strats,
7979
)
8080
def test_union_field_roundtrip(cl_and_vals_a, cl_and_vals_b, strat):
@@ -116,8 +116,8 @@ def handler(obj, _):
116116
@pytest.mark.skipif(not is_py310_plus, reason="3.10+ union syntax")
117117
@settings(suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow])
118118
@given(
119-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False),
120-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False),
119+
simple_typed_classes(defaults="never", newtypes=False, allow_nan=False),
120+
simple_typed_classes(defaults="never", newtypes=False, allow_nan=False),
121121
unstructure_strats,
122122
)
123123
def test_310_union_field_roundtrip(cl_and_vals_a, cl_and_vals_b, strat):
@@ -156,7 +156,7 @@ def handler(obj, _):
156156
assert inst == converter.structure(converter.unstructure(inst), C)
157157

158158

159-
@given(simple_typed_classes(defaults=False, newtypes=False, allow_nan=False))
159+
@given(simple_typed_classes(defaults="never", newtypes=False, allow_nan=False))
160160
def test_optional_field_roundtrip(cl_and_vals):
161161
"""
162162
Classes with optional fields can be unstructured and structured.
@@ -178,7 +178,7 @@ class C:
178178

179179

180180
@pytest.mark.skipif(not is_py310_plus, reason="3.10+ union syntax")
181-
@given(simple_typed_classes(defaults=False, newtypes=False, allow_nan=False))
181+
@given(simple_typed_classes(defaults="never", newtypes=False, allow_nan=False))
182182
def test_310_optional_field_roundtrip(cl_and_vals):
183183
"""
184184
Classes with optional fields can be unstructured and structured.

tests/test_converter.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_simple_roundtrip_tuple(cls_and_vals, dv: bool):
7777
assert inst == converter.structure(unstructured, cl)
7878

7979

80-
@given(simple_typed_attrs(defaults=True, allow_nan=False))
80+
@given(simple_typed_attrs(defaults="always", allow_nan=False))
8181
def test_simple_roundtrip_defaults(attr_and_vals):
8282
"""
8383
Simple classes with metadata can be unstructured and restructured.
@@ -93,7 +93,9 @@ def test_simple_roundtrip_defaults(attr_and_vals):
9393

9494

9595
@given(
96-
simple_typed_attrs(defaults=True, kw_only=False, newtypes=False, allow_nan=False)
96+
simple_typed_attrs(
97+
defaults="always", kw_only=False, newtypes=False, allow_nan=False
98+
)
9799
)
98100
def test_simple_roundtrip_defaults_tuple(attr_and_vals):
99101
"""
@@ -173,7 +175,7 @@ class C:
173175
converter.structure(unstructured, C)
174176

175177

176-
@given(simple_typed_attrs(defaults=True))
178+
@given(simple_typed_attrs(defaults="always"))
177179
def test_forbid_extra_keys_defaults(attr_and_vals):
178180
"""
179181
Restructuring fails when a dict key is renamed (if forbid_extra_keys set)
@@ -234,7 +236,9 @@ class A:
234236
assert cve.value.exceptions[0].extra_fields == {"b"}
235237

236238

237-
@given(nested_typed_classes(defaults=True, min_attrs=1, allow_nan=False), booleans())
239+
@given(
240+
nested_typed_classes(defaults="always", min_attrs=1, allow_nan=False), booleans()
241+
)
238242
def test_nested_roundtrip(cls_and_vals, omit_if_default):
239243
"""
240244
Nested classes with metadata can be unstructured and restructured.
@@ -249,7 +253,7 @@ def test_nested_roundtrip(cls_and_vals, omit_if_default):
249253

250254
@given(
251255
nested_typed_classes(
252-
defaults=True, min_attrs=1, kw_only=False, newtypes=False, allow_nan=False
256+
defaults="always", min_attrs=1, kw_only=False, newtypes=False, allow_nan=False
253257
),
254258
booleans(),
255259
)
@@ -269,8 +273,12 @@ def test_nested_roundtrip_tuple(cls_and_vals, omit_if_default: bool):
269273

270274
@settings(suppress_health_check=[HealthCheck.too_slow])
271275
@given(
272-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False, min_attrs=2),
273-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False, min_attrs=1),
276+
simple_typed_classes(
277+
defaults="never", newtypes=False, allow_nan=False, min_attrs=2
278+
),
279+
simple_typed_classes(
280+
defaults="never", newtypes=False, allow_nan=False, min_attrs=1
281+
),
274282
)
275283
def test_union_field_roundtrip_dict(cl_and_vals_a, cl_and_vals_b):
276284
"""
@@ -334,8 +342,8 @@ def handler(obj, _):
334342
@pytest.mark.skipif(not is_py310_plus, reason="3.10+ union syntax")
335343
@settings(suppress_health_check=[HealthCheck.filter_too_much, HealthCheck.too_slow])
336344
@given(
337-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False),
338-
simple_typed_classes(defaults=False, newtypes=False, allow_nan=False),
345+
simple_typed_classes(defaults="never", newtypes=False, allow_nan=False),
346+
simple_typed_classes(defaults="never", newtypes=False, allow_nan=False),
339347
unstructure_strats,
340348
)
341349
def test_310_union_field_roundtrip(cl_and_vals_a, cl_and_vals_b, strat):
@@ -398,7 +406,7 @@ class C:
398406

399407

400408
@pytest.mark.skipif(not is_py310_plus, reason="3.10+ union syntax")
401-
@given(simple_typed_classes(defaults=False, allow_nan=False))
409+
@given(simple_typed_classes(defaults="never", allow_nan=False))
402410
def test_310_optional_field_roundtrip(cl_and_vals):
403411
"""
404412
Classes with optional fields can be unstructured and structured.
@@ -419,7 +427,7 @@ class C:
419427
assert inst == converter.structure(unstructured, C)
420428

421429

422-
@given(simple_typed_classes(defaults=True, allow_nan=False))
430+
@given(simple_typed_classes(defaults="always", allow_nan=False))
423431
def test_omit_default_roundtrip(cl_and_vals):
424432
"""
425433
Omit default on the converter works.
@@ -460,7 +468,7 @@ class C:
460468
assert converter.structure(unstructured, C) == inst
461469

462470

463-
@given(simple_typed_classes(defaults=True))
471+
@given(simple_typed_classes(defaults="always"))
464472
def test_type_overrides(cl_and_vals):
465473
"""
466474
Type overrides on the GenConverter work.

0 commit comments

Comments
 (0)