示例#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))
示例#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)
示例#3
0
 def dumps(obj) -> str:
     obj = Serializer.serialize(obj)
     return serialize_yaml(obj)
示例#4
0
 def loads(obj: str):
     obj = deserialize_yaml(obj)
     return Serializer.deserialize(obj)
示例#5
0
文件: json.py 项目: fedjaz/Labs
 def dumps(obj) -> str:
     obj = Serializer.serialize(obj)
     return serialize_json(obj).replace("\n", "\\n")
示例#6
0
文件: json.py 项目: fedjaz/Labs
 def loads(obj: str):
     obj = deserialize_json(obj.replace("\\n", "\n"))
     return Serializer.deserialize(obj)
示例#7
0
def serialize_and_compare_obj(obj, tester):
    s = Serializer()
    ser = s.serialize(obj)
    res = s.deserialize(ser)
    tester.assertEqual(res, obj)
示例#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))
示例#9
0
文件: toml.py 项目: fedjaz/Labs
 def dumps(obj) -> str:
     obj = Serializer.serialize(obj)
     return f"tuple = {serialize_toml(obj)}"
示例#10
0
文件: toml.py 项目: fedjaz/Labs
    def loads(obj: str):
        obj = obj.split('=', 1)[1]

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