def test_dataclass_with_x_caches_class(self): json_dataclass_with_x = '{"x": 1}' _ = DataClassX.from_json(json_dataclass_with_x) # type hints for class cached assert _get_type_hints_cache._Cache__currsize == 1 # supported generic called for int assert _is_supported_generic_cache._Cache__currsize == 1 # for the dataclass assert _user_overrides_cache._Cache__currsize == 1 # force cache hits _ = DataClassX.from_json(json_dataclass_with_x) assert _get_type_hints_cache._Cache__currsize == 1 assert _is_supported_generic_cache._Cache__currsize == 1 assert _user_overrides_cache._Cache__currsize == 1
def test_wrong_nested_list_of_dataclasses(self): try: _ = DataClassX.from_json('{"a": "incorrect_field"}') x_error = None except Exception as e: x_error = e assert x_error is not None try: _ = DataClassXs.from_json('{"xs": [{"a": "incorrect_field"}]}') xs_error = None except Exception as e: xs_error = e assert xs_error is not None assert x_error.__class__ == xs_error.__class__ assert x_error.args == xs_error.args
def test_nested_list_of_dataclasses(self): assert (DataClassXs([DataClassX(0), DataClassX(1) ]).to_json() == '{"xs": [{"x": 0}, {"x": 1}]}')