From 8621cd3f43e386161c8474485ef32e657ab4569e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tin=20Tvrtkovi=C4=87?= Date: Sat, 19 Oct 2024 22:24:10 +0200 Subject: [PATCH] More coverage --- tests/test_gen_dict.py | 4 +++- tests/test_gen_dict_563.py | 2 +- tests/test_generics.py | 22 ++++++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/test_gen_dict.py b/tests/test_gen_dict.py index d60a5d74..6bb61a6b 100644 --- a/tests/test_gen_dict.py +++ b/tests/test_gen_dict.py @@ -336,6 +336,7 @@ def test_overriding_struct_hook(converter: BaseConverter) -> None: class A: a: int b: str + c: int = 0 converter.register_structure_hook( A, @@ -343,11 +344,12 @@ class A: A, converter, a=override(struct_hook=lambda v, _: ceil(v)), + c=override(struct_hook=lambda v, _: ceil(v)), _cattrs_detailed_validation=converter.detailed_validation, ), ) - assert converter.structure({"a": 0.5, "b": 1}, A) == A(1, "1") + assert converter.structure({"a": 0.5, "b": 1, "c": 0.5}, A) == A(1, "1", 1) def test_overriding_unstruct_hook(converter: BaseConverter) -> None: diff --git a/tests/test_gen_dict_563.py b/tests/test_gen_dict_563.py index f81582b2..be5503ad 100644 --- a/tests/test_gen_dict_563.py +++ b/tests/test_gen_dict_563.py @@ -4,7 +4,7 @@ from dataclasses import dataclass -from attr import define +from attrs import define from cattrs import Converter from cattrs.gen import make_dict_structure_fn, make_dict_unstructure_fn diff --git a/tests/test_generics.py b/tests/test_generics.py index 5e846ed2..f9d46489 100644 --- a/tests/test_generics.py +++ b/tests/test_generics.py @@ -14,6 +14,7 @@ T = TypeVar("T") T2 = TypeVar("T2") +T3 = TypeVar("T3", bound=int) def test_deep_copy(): @@ -31,9 +32,10 @@ def test_deep_copy(): @define -class TClass(Generic[T, T2]): +class TClass(Generic[T, T2, T3]): a: T b: T2 + c: T3 = 0 @define @@ -44,15 +46,15 @@ class GenericCols(Generic[T]): @pytest.mark.parametrize( - ("t", "t2", "result"), + ("t", "t2", "t3", "result"), ( - (int, str, TClass(1, "a")), - (str, str, TClass("1", "a")), - (List[int], str, TClass([1, 2, 3], "a")), + (int, str, int, TClass(1, "a")), + (str, str, int, TClass("1", "a")), + (List[int], str, int, TClass([1, 2, 3], "a")), ), ) -def test_able_to_structure_generics(converter: BaseConverter, t, t2, result): - res = converter.structure(asdict(result), TClass[t, t2]) +def test_able_to_structure_generics(converter: BaseConverter, t, t2, t3, result): + res = converter.structure(asdict(result), TClass[t, t2, t3]) assert res == result @@ -105,8 +107,8 @@ class GenericCols(Generic[T]): @pytest.mark.parametrize( ("t", "t2", "result"), ( - (TClass[int, int], str, TClass(TClass(1, 2), "a")), - (List[TClass[int, int]], str, TClass([TClass(1, 2)], "a")), + (TClass[int, int, int], str, TClass(TClass(1, 2), "a")), + (List[TClass[int, int, int]], str, TClass([TClass(1, 2)], "a")), ), ) def test_structure_nested_generics(converter: BaseConverter, t, t2, result): @@ -116,7 +118,7 @@ def test_structure_nested_generics(converter: BaseConverter, t, t2, result): def test_able_to_structure_deeply_nested_generics_gen(converter): - cl = TClass[TClass[TClass[int, int], int], int] + cl = TClass[TClass[TClass[int, int, int], int, int], int, int] result = TClass(TClass(TClass(1, 2), 3), 4) res = converter.structure(asdict(result), cl)