def test_read_jsonnet(self): with pytest.raises(RuntimeError): Params.from_file(self.FIXTURES_ROOT / "configs" / "resnet50_unet_bad.jsonnet") params = Params.from_file(self.FIXTURES_ROOT / "configs" / "resnet50_unet.jsonnet") assert len(params) == 3 assert params["encoder"]["type"] == "resnet50" assert params["decoder"]["type"] == "unet" assert params["decoder"]["decoder_channels"] == [512, 256, 128, 64, 32]
def test_write_read_from_file(self): config_dict = {"test": "hello"} params = Params(config_dict) assert params.as_dict() == config_dict write_path = self.TEMPORARY_DIR / "dummy_config.json" params.to_file(str(write_path)) params2 = Params.from_file(str(write_path)) assert params.as_dict() == params2.as_dict() assert params.pop("test") == "hello" assert params.pop("test2", "none") == "none" with pytest.raises(ConfigurationError): params.pop("test")