MCPcopy Create free account
hub / github.com/modelscope/modelscope / test_format

Method test_format

tests/fileio/test_io.py:12–38  ·  view source on GitHub ↗
(self, format='json')

Source from the content-addressed store, hash-verified

10class FileIOTest(unittest.TestCase):
11
12 def test_format(self, format='json'):
13 obj = [1, 2, 3, 'str', {'model': 'resnet'}, [1, 2]]
14 result_str = dumps(obj, format)
15 temp_name = tempfile.gettempdir() + '/' + next(
16 tempfile._get_candidate_names()) + '.' + format
17 dump(obj, temp_name)
18 obj_load = load(temp_name)
19
20 self.assertEqual(len(obj), len(obj_load))
21 for i, obj_i in enumerate(obj):
22 if isinstance(obj_i, list):
23 self.assertListEqual(obj_i, obj_load[i])
24 elif isinstance(obj_i, np.ndarray):
25 self.assertListEqual(obj_i.tolist(), obj_load[i].tolist())
26 elif isinstance(obj_i, dict):
27 self.assertDictEqual(obj_i, obj_load[i])
28 else:
29 self.assertEqual(obj_i, obj_load[i])
30
31 with open(temp_name, 'r') as infile:
32 self.assertEqual(result_str, infile.read())
33
34 with self.assertRaises(TypeError):
35 obj_load = load(temp_name + 's')
36
37 with self.assertRaises(TypeError):
38 dump(obj, temp_name + 's')
39
40 def test_yaml(self):
41 self.test_format('yaml')

Callers 1

test_yamlMethod · 0.95

Calls 4

dumpsFunction · 0.90
dumpFunction · 0.90
loadFunction · 0.90
readMethod · 0.45

Tested by

no test coverage detected