From 53114bf1812ab9ba440d1125cd36a34a3d0dfab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20Tvrtkovi=C4=87?= Date: Mon, 2 Dec 2024 23:20:40 +0100 Subject: [PATCH] Improve cols coverage --- tests/test_tuples.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/test_tuples.py b/tests/test_tuples.py index a6729abc..4fcfd85e 100644 --- a/tests/test_tuples.py +++ b/tests/test_tuples.py @@ -69,19 +69,25 @@ class Test(NamedTuple): def test_simple_dict_nametuples(genconverter: Converter): """Namedtuples can be un/structured to/from dicts.""" + class TestInner(NamedTuple): + a: int + class Test(NamedTuple): a: int b: str = "test" + c: TestInner = TestInner(1) genconverter.register_unstructure_hook_factory( - lambda t: t is Test, namedtuple_dict_unstructure_factory + lambda t: t in (Test, TestInner), namedtuple_dict_unstructure_factory ) genconverter.register_structure_hook_factory( - lambda t: t is Test, namedtuple_dict_structure_factory + lambda t: t in (Test, TestInner), namedtuple_dict_structure_factory ) - assert genconverter.unstructure(Test(1)) == {"a": 1, "b": "test"} - assert genconverter.structure({"a": 1, "b": "2"}, Test) == Test(1, "2") + assert genconverter.unstructure(Test(1)) == {"a": 1, "b": "test", "c": {"a": 1}} + assert genconverter.structure({"a": 1, "b": "2"}, Test) == Test( + 1, "2", TestInner(1) + ) # Defaults work. assert genconverter.structure({"a": 1}, Test) == Test(1, "test")