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))
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)
def dumps(obj) -> str: obj = Serializer.serialize(obj) return serialize_yaml(obj)
def loads(obj: str): obj = deserialize_yaml(obj) return Serializer.deserialize(obj)
def dumps(obj) -> str: obj = Serializer.serialize(obj) return serialize_json(obj).replace("\n", "\\n")
def loads(obj: str): obj = deserialize_json(obj.replace("\\n", "\n")) return Serializer.deserialize(obj)
def serialize_and_compare_obj(obj, tester): s = Serializer() ser = s.serialize(obj) res = s.deserialize(ser) tester.assertEqual(res, obj)
def serialize_and_compare_func(func, tester): s = Serializer() ser = s.serialize(func) res = s.deserialize(ser) tester.assertEqual(res(5), func(5))
def dumps(obj) -> str: obj = Serializer.serialize(obj) return f"tuple = {serialize_toml(obj)}"
def loads(obj: str): obj = obj.split('=', 1)[1] obj = deserialize_toml(obj.replace("\\n", "\n").strip()) return Serializer.deserialize(obj)