Example #1
0
 def test_complex_dict(self):
     s = Serializer()
     ser = s.serialize(test_dict_func)
     res = s.deserialize(ser)
     f1 = list(res)[0]
     f2 = res[f1]
     self.assertEqual(f1(5), test_wrapper(5))
     self.assertEqual(f2(5), test_fact(5))
Example #2
0
    def test_multiple_serialization(self):
        s = Serializer()
        ser = s.serialize(test_list)
        ser = s.serialize(ser)
        ser = s.serialize(ser)
        ser = s.serialize(ser)

        res = s.deserialize(ser)
        res = s.deserialize(res)
        res = s.deserialize(res)
        res = s.deserialize(res)

        self.assertEqual(res, test_list)
Example #3
0
 def dumps(obj) -> str:
     obj = Serializer.serialize(obj)
     return serialize_yaml(obj)
Example #4
0
 def loads(obj: str):
     obj = deserialize_yaml(obj)
     return Serializer.deserialize(obj)
Example #5
0
File: json.py Project: fedjaz/Labs
 def dumps(obj) -> str:
     obj = Serializer.serialize(obj)
     return serialize_json(obj).replace("\n", "\\n")
Example #6
0
File: json.py Project: fedjaz/Labs
 def loads(obj: str):
     obj = deserialize_json(obj.replace("\\n", "\n"))
     return Serializer.deserialize(obj)
Example #7
0
def serialize_and_compare_obj(obj, tester):
    s = Serializer()
    ser = s.serialize(obj)
    res = s.deserialize(ser)
    tester.assertEqual(res, obj)
Example #8
0
def serialize_and_compare_func(func, tester):
    s = Serializer()
    ser = s.serialize(func)
    res = s.deserialize(ser)
    tester.assertEqual(res(5), func(5))
Example #9
0
File: toml.py Project: fedjaz/Labs
 def dumps(obj) -> str:
     obj = Serializer.serialize(obj)
     return f"tuple = {serialize_toml(obj)}"
Example #10
0
File: toml.py Project: fedjaz/Labs
    def loads(obj: str):
        obj = obj.split('=', 1)[1]

        obj = deserialize_toml(obj.replace("\\n", "\n").strip())
        return Serializer.deserialize(obj)