def test_instance_instance_deserialisation(reset_registry) -> None: class Name123(static.StaticData): """Test class.""" a: int = static.STATIC b: int c: Dict[str, int] @dataclasses.dataclass class GoodBoy(metaclass=Name123): """Test class.""" __species__ = 'WolfoInDogClothes' a = 1 b: int c: Dict[str, int] doggo = GoodBoy(b=2, c={ 'age_in_dog_years': 100, }) assert 'GoodBoy' not in globals() globals()['GoodBoy'] = GoodBoy try: one = serialisation.unjsonify({'$module': GoodBoy.__module__, '$type': GoodBoy.__name__, 'b': 2, 'c': {'ageInDogYears': 100}}) assert one == doggo assert one is not doggo two = serialisation.unjsonify({'$module': GoodBoy.__module__, '$type': GoodBoy.__name__, 'b': 2, 'c': {'ageInDogYears': 100}}, camel_case_keys=True) assert two == doggo assert two is not doggo three = serialisation.unjsonify({'$module': GoodBoy.__module__, '$type': GoodBoy.__name__, 'b': 2, 'c': {'age_in_dog_years': 100}}, camel_case_keys=False) assert three == doggo assert three is not doggo finally: del globals()['GoodBoy']
def test_unjsonify(obj: Any, expected: Any) -> None: val = serialisation.unjsonify(obj) try: assert val == expected except AssertionError: pass else: return assert _replace_nan(val) == _replace_nan(expected)
def test_unjsonify_snake(obj: Any, expected: Any) -> None: val = serialisation.unjsonify(obj, camel_case_keys=False) try: assert val == expected except AssertionError: pass else: return assert _replace_nan(val) == _replace_nan(expected)
def test_unjsonify_raises(obj: Any, expected: Any) -> None: with pytest.raises(expected): serialisation.unjsonify(obj)
def test_unjsonify_camel_raises(obj: Any, expected: Any) -> None: with pytest.raises(expected): serialisation.unjsonify(obj, camel_case_keys=True)
def test_instance_deserialisation(reset_registry) -> None: class Name123(static.StaticData): """Test class.""" b: int = static.STATIC c: Dict[str, int] = static.STATIC assert 'Name123' not in globals() globals()['Name123'] = Name123 try: class GoodBoy(metaclass=Name123): """He's a good boy.""" b = 2 c = {'age_in_dog_years': 100} one = serialisation.unjsonify({ '$module': Name123.__module__, '$type': Name123.__name__, 'name': 'GoodBoy', 'b': 2, 'c': {'ageInDogYears': 100} }) two = serialisation.unjsonify({ '$module': Name123.__module__, '$type': Name123.__name__, 'name': 'GoodBoy', 'b': 2, 'c': {'ageInDogYears': 100} }, camel_case_keys=True) three = serialisation.unjsonify({ '$module': Name123.__module__, '$type': Name123.__name__, 'name': 'GoodBoy', 'b': 2, 'c': {'age_in_dog_years': 100} }, camel_case_keys=False) fresh = serialisation.unjsonify({ '$module': Name123.__module__, '$type': Name123.__name__, 'name': 'FreshBoy', 'b': 3, 'c': {'ageInDogYears': 10} }) assert one in GoodBoy assert two is GoodBoy assert three is GoodBoy assert fresh.__name__ == 'FreshBoy' assert fresh.__module__ == static.__name__ assert isinstance(fresh, Name123) assert fresh in Name123 assert fresh is not GoodBoy assert fresh is Name123.FreshBoy assert fresh.b == 3 assert fresh.c == {'age_in_dog_years': 10} finally: del globals()['Name123']