Пример #1
0
 def test_serde(self, obj):
     encoded = to_json(obj)
     decoded = from_json(encoded)
     if isinstance(obj, np.ndarray):
         assert np.array_equal(decoded, obj)
     else:
         assert decoded == obj
Пример #2
0
 def test_registered(self):
     d = Dummy(x=-1)
     d_json = to_json(d)
     assert encode(d) == {"x": d.x, constants.TYPE_MARKER: "Dummy"}
     expected = '{{\n    "x": {:},\n    "{:}": "Dummy"\n}}'.format(
         d.x, constants.TYPE_MARKER)
     assert d_json == expected
Пример #3
0
 def test_registered(self):
     d = Dummy(x=-1)
     d_json = to_json(d)
     assert encode(d) == {
         'x': d.x,
         '__polygraphy_encoded_Dummy': constants.TYPE_MARKER
     }
     expected = "{{\n    \"x\": {:},\n    \"__polygraphy_encoded_Dummy\": \"{:}\"\n}}".format(
         d.x, constants.TYPE_MARKER)
     assert d_json == expected
Пример #4
0
    def test_object_pairs_hook(self):
        d = Dummy(x=-1)
        d_json = to_json(d)

        new_d = from_json(d_json)
        assert new_d.x == d.x