def test_load_json_filename(): # type: ignore with tempfile.NamedTemporaryFile() as f: f.file.write(JSON.encode()) f.file.flush() cfg = config_from_json(f.name, read_from_file=True) assert cfg["a1.b1.c1"] == 1 assert cfg["a1.b1"].as_dict() == {"c1": 1, "c2": 2, "c3": 3} assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1} assert cfg == config_from_dict(DICT)
def test_reload_json(): # type: ignore with tempfile.NamedTemporaryFile() as f: f.file.write(JSON.encode()) f.file.flush() cfg = config_from_json(f.name, read_from_file=True) assert cfg == config_from_dict(DICT) f.file.seek(0) f.file.truncate(0) f.file.write(b'{"test": 1}') f.file.flush() cfg.reload() assert cfg == config_from_dict({"test": 1})
"Sample UID has correct namespace", ) tc.assertTrue( str(sample.get_resource("label_gt")).startswith(f"{dataset.namespace()}::"), "Sample label has correct namespace", ) if deep: # Attemt to load input image sample.get_resource("input_img_np") if __name__ == "__main__": parser = argparse.ArgumentParser() gp = parser.add_mutually_exclusive_group(required=True) gp.add_argument("--name", type=str) gp.add_argument("--json", type=str) parser.add_argument("--deep", action="store_true") parser.add_argument("--statistics", action="store_true") args = parser.parse_args() if args.name is not None: config = {"name": args.name} elif args.json is not None: import config as pcfg configs = [pcfg.config_from_json(args.json, read_from_file=True)] config = pcfg.ConfigurationSet(*configs) validate(config, args.deep, args.statistics)
def test_equality(): # type: ignore cfg = config_from_json(JSON) assert cfg == config_from_dict(DICT)
def test_load_json(): # type: ignore cfg = config_from_json(JSON) assert cfg["a1.b1.c1"] == 1 assert cfg["a1.b1"].as_dict() == {"c1": 1, "c2": 2, "c3": 3} assert cfg["a1.b2"].as_dict() == {"c1": "a", "c2": True, "c3": 1.1}