Beispiel #1
0
    def test_to_dict(self):
        x = JsonObject(foo="a", bar=10)
        self.assertEquals(dict(foo="a", bar=10), x.to_dict())

        x = JsonObject(foo=JsonObject(bee=1), bar=10)
        self.assertEquals(dict(foo=dict(bee=1), bar=10), x.to_dict())

        x = JsonObject(foo=dict(bee=1, boo=JsonObject(hi=True)), bar=10)
        self.assertEquals(dict(foo=dict(bee=1, boo=dict(hi=True)), bar=10),
                          x.to_dict())

        x = JsonObject(foo=JsonArray(1, 2, 3), bar=10)
        self.assertEquals(dict(foo=[1, 2, 3], bar=10), x.to_dict())

        x = JsonObject(foo=[1, 2, JsonObject(foo=5)], bar=10)
        self.assertEquals(dict(foo=[1, 2, dict(foo=5)], bar=10), x.to_dict())
Beispiel #2
0
    def test_json_object_to_dict_memory_leak(self):
        content = {"foo": "bar", "a": 2, "b": [1, 2, 3]}

        # New object
        for index in range(0, 50):
            json_object = JsonObject(content=content)
            dict_value = json_object.to_dict()
            self.assertEqual(content, dict_value)

            self.assertNoNewGarbage()

        # Existing object
        json_object = JsonObject(content=content)

        for index in range(0, 50):
            dict_value = json_object.to_dict()
            self.assertEqual(content, dict_value)
            self.assertNoNewGarbage()