Example #1
0
    def test_hint_with_jsonserializable(self):
        from version_with_dataclasses import HolderWithJsonSerializable, Person

        h = HolderWithJsonSerializable(Person('John'))
        expected = {'x': {'name': 'John'}}
        dumped = h.dump()
        self.assertDictEqual(expected, dumped)

        h = HolderWithJsonSerializable(Person('John'))
        expected2 = {'x': {}}
        dumped2 = h.dump(strict=True)
        self.assertDictEqual(expected2, dumped2)
Example #2
0
    def test_simple_dump_and_load_dataclass(self):
        from version_with_dataclasses import Person
        p = Person('John')
        dumped = jsons.dump(p)
        loaded = jsons.load(dumped, Person)
        self.assertEqual(p.name, loaded.name)

        with self.assertRaises(SignatureMismatchError):
            jsons.load({'name': 'John', 'age': 88}, Person, strict=True)