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

Method test_dump

tests/utils/test_config.py:34–54  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

32 self.assertEqual(cfg.b, obj['b'])
33
34 def test_dump(self):
35 config_file = 'configs/examples/configuration.py'
36 cfg = Config.from_file(config_file)
37 self.assertEqual(cfg.a, 1)
38 self.assertEqual(cfg.b, obj['b'])
39 pretty_text = 'a = 1\n'
40 pretty_text += "b = dict(c=[1, 2, 3], d='dd')\n"
41
42 json_str = '{"a": 1, "b": {"c": [1, 2, 3], "d": "dd"}}'
43 yaml_str = 'a: 1\nb:\n c:\n - 1\n - 2\n - 3\n d: dd\n'
44 with tempfile.NamedTemporaryFile(suffix='.json') as ofile:
45 self.assertEqual(pretty_text, cfg.dump())
46 cfg.dump(ofile.name)
47 with open(ofile.name, 'r') as infile:
48 self.assertDictEqual(
49 json.loads(json_str), json.loads(infile.read()))
50
51 with tempfile.NamedTemporaryFile(suffix='.yaml') as ofile:
52 cfg.dump(ofile.name)
53 with open(ofile.name, 'r') as infile:
54 self.assertEqual(yaml_str, infile.read())
55
56 def test_to_dict(self):
57 config_file = 'configs/examples/configuration.json'

Callers

nothing calls this directly

Calls 3

from_fileMethod · 0.80
dumpMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected