Exemplo n.º 1
0
 def test_macro_replace(self):
     with tempfile.TemporaryDirectory() as tempdir:
         another_file = os.path.join(tempdir, "another.json")
         ConfigParser.export_config_file(config={"E": 4}, filepath=another_file)
         # test macro with id, relative id, and macro in another file
         config = {"A": {"B": 1, "C": 2}, "D": [3, "%A#B", "%#0", f"%{another_file}#E"]}
         parser = ConfigParser(config=config)
         parser.resolve_macro_and_relative_ids()
         self.assertEqual(str(parser.get()), str({"A": {"B": 1, "C": 2}, "D": [3, 1, 3, 4]}))
Exemplo n.º 2
0
 def test_config_content(self):
     test_config = {"preprocessing": [{"_target_": "LoadImage"}], "dataset": {"_target_": "Dataset"}}
     parser = ConfigParser(config=test_config)
     # test `get`, `set`, `__getitem__`, `__setitem__`
     self.assertEqual(str(parser.get()), str(test_config))
     parser.set(config=test_config)
     self.assertListEqual(parser["preprocessing"], test_config["preprocessing"])
     parser["dataset"] = {"_target_": "CacheDataset"}
     self.assertEqual(parser["dataset"]["_target_"], "CacheDataset")
     # test nested ids
     parser["dataset#_target_"] = "Dataset"
     self.assertEqual(parser["dataset#_target_"], "Dataset")
     # test int id
     parser.set(["test1", "test2", "test3"])
     parser[1] = "test4"
     self.assertEqual(parser[1], "test4")