def serialize(dest_format, path_file):
    serializer = Factory.create_serializer(dest_format)
    try:
        src_format = Path(path_file).suffix
        if src_format == dest_format:
            return
        deserializer = Factory.create_serializer(src_format)
        abs_path = Path(path_file)
        loaded = deserializer.load(path_file)
        serializer.dump(loaded,
                        Path(abs_path.parent, f"{abs_path.stem}{dest_format}"))
    except FileNotFoundError:
        print("wrong path or format")
Beispiel #2
0
 def test_json_cmplx_func(self):
     self.s = Factory.create_serializer('.json')
     old_obj = test_source.cmplx_func
     old_obj_2 = test_source.simple_lambda
     new_obj = self.s.loads(self.s.dumps(old_obj))
     new_obj_2 = self.s.loads(self.s.dumps(old_obj_2))
     self.assertEqual(old_obj(4), new_obj(4))
     self.assertEqual(old_obj_2(4), new_obj_2(4))
Beispiel #3
0
 def test_json_cmplx_class_obj(self):
     self.s = Factory.create_serializer('.json')
     old_obj = test_source.ComplexClass()
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj.simple_class.word, new_obj.simple_class.word)
     self.assertEqual(old_obj.func_with_glob(),
                      new_obj.func_with_glob(new_obj))
     self.assertEqual(old_obj.const, new_obj.const)
     self.assertEqual(old_obj.simple_class.say_kuku(),
                      new_obj.simple_class.say_kuku(new_obj.simple_class))
Beispiel #4
0
 def test_json_simple_class_obj(self):
     self.s = Factory.create_serializer('.json')
     old_obj = test_source.SimpleClass()
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj.say_kuku(), new_obj.say_kuku(new_obj))
     self.assertEqual(old_obj.word, new_obj.word)
Beispiel #5
0
 def test_json_int(self):
     self.s = Factory.create_serializer('.json')
     old_obj = test_source.int_glob
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj, new_obj)
Beispiel #6
0
 def test_json_lambda(self):
     self.s = Factory.create_serializer('.json')
     old_obj = test_source.simple_lambda
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj(5), new_obj(5))
Beispiel #7
0
 def test_json_simple_func(self):
     self.s = Factory.create_serializer('.json')
     old_obj = test_source.simple_func
     self.s.dump(old_obj, 'test.json')
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj(4), new_obj(4))
Beispiel #8
0
 def test_pickle_cmplx_func(self):
     self.s = Factory.create_serializer('.pickle')
     old_obj = test_source.cmplx_func
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj(4), new_obj(4))
Beispiel #9
0
 def test_json_dict(self):
     self.s = Factory.create_serializer('.json')
     old_obj = test_source.dict_1
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj['Name'], new_obj['Name'])
Beispiel #10
0
 def test_pickle_dict(self):
     self.s = Factory.create_serializer('.pickle')
     old_obj = test_source.dict_1
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj, new_obj)
Beispiel #11
0
 def test_pickle_boolean(self):
     self.s = Factory.create_serializer('.pickle')
     old_obj = test_source.boolean_glob
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj, new_obj)
Beispiel #12
0
 def test_toml_set(self):
     self.s = Factory.create_serializer('.toml')
     old_obj = test_source.set_1
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj, new_obj)
Beispiel #13
0
 def test_yaml_tuple(self):
     self.s = Factory.create_serializer('.yaml')
     old_obj = test_source.tuple_1
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj, new_obj)
Beispiel #14
0
 def test_yaml_float(self):
     self.s = Factory.create_serializer('.yaml')
     old_obj = test_source.float_glob
     new_obj = self.s.loads(self.s.dumps(old_obj))
     self.assertEqual(old_obj, new_obj)