Esempio n. 1
0
    def test_dict_serializing_no_int_keys(self):
        obj = {
            "abc": TestClass(1, "a", 2, "b"),
            "123": "def",
            "hij": [TestClass(3, "c", 4, "d"), "klm", 456],
        }

        dumped = custom_dumps(obj)
        loaded = custom_loads(dumped)
        self.assertEqual(obj, loaded)
Esempio n. 2
0
 def test_nested_list_serializing(self):
     obj = [
         123,
         "abc",
         TestClass(1, "a", 2, "b"),
         [234, "def", TestClass(2, "b", 3, "c")],
     ]
     dumped = custom_dumps(obj)
     loaded = custom_loads(dumped)
     self.assertEqual(obj, loaded)
Esempio n. 3
0
    def test_dict_serializing_int_keys(self):
        # Unfortunately JSON doesnt support dict keys as ints so they will automatically
        # get converted. Hopefully this wont be an issue in SimpleML, but be aware...
        obj = {
            "abc": TestClass(1, "a", 2, "b"),
            123: "def",
            "hij": [TestClass(3, "c", 4, "d"), "klm", 456],
        }

        expected_obj = {
            "abc": TestClass(1, "a", 2, "b"),
            "123": "def",
            "hij": [TestClass(3, "c", 4, "d"), "klm", 456],
        }
        dumped = custom_dumps(obj)
        loaded = custom_loads(dumped)
        self.assertNotEqual(obj, loaded)
        self.assertEqual(loaded, expected_obj)
Esempio n. 4
0
 def test_list_serializing(self):
     obj = [123, "abc", TestClass(1, "a", 2, "b")]
     dumped = custom_dumps(obj)
     loaded = custom_loads(dumped)
     self.assertEqual(obj, loaded)
Esempio n. 5
0
 def test_number_serializing(self):
     obj = 123
     dumped = custom_dumps(obj)
     loaded = custom_loads(dumped)
     self.assertEqual(obj, loaded)
Esempio n. 6
0
 def test_top_level_serializing(self):
     obj = TestClass(1, "a", 2, "b")
     dumped = custom_dumps(obj)
     loaded = custom_loads(dumped)
     self.assertEqual(obj, loaded)