def test_existing_config_file_different_parameters(self): """ on a user defined mss_settings_json without a defined num_labels this test should return its default value """ create_mss_settings_file('{"num_interpolation_points": 20 }') if not fs.open_fs(MSS_CONFIG_PATH).exists("mss_settings.json"): pytest.skip('undefined test mss_settings.json') with fs.open_fs(MSS_CONFIG_PATH) as file_dir: file_content = file_dir.readtext("mss_settings.json") assert "num_labels" not in file_content config_file = fs.path.combine(MSS_CONFIG_PATH, "mss_settings.json") data = utils.config_loader(config_file=config_file) assert data["num_labels"] == 10 num_labels = utils.config_loader(config_file=config_file, dataset="num_labels") assert num_labels == 10 num_interpolation_points = utils.config_loader( config_file=config_file, dataset="num_interpolation_points") assert num_interpolation_points == 20 data = utils.config_loader(config_file=config_file) assert data["num_interpolation_points"] == 20 with pytest.raises(KeyError): utils.config_loader(config_file=config_file, dataset="UNDEFINED") with pytest.raises(KeyError): assert utils.config_loader(config_file=config_file, dataset="UNDEFINED")
def test_existing_empty_config_file(self): """ on a user defined empty mss_settings_json this test should return the default value for num_labels """ create_mss_settings_file('{ }') if not fs.open_fs(MSS_CONFIG_PATH).exists("mss_settings.json"): pytest.skip('undefined test mss_settings.json') with fs.open_fs(MSS_CONFIG_PATH) as file_dir: file_content = file_dir.readtext("mss_settings.json") assert ":" not in file_content config_file = fs.path.combine(MSS_CONFIG_PATH, "mss_settings.json") data = utils.config_loader(config_file=config_file) assert data["num_labels"] == 10 num_labels = utils.config_loader(config_file=config_file, dataset="num_labels") assert num_labels == 10 # this overwrites the builtin default value num_labels = utils.config_loader(config_file=config_file, dataset="num_labels") assert num_labels == 10 with pytest.raises(KeyError): utils.config_loader(config_file=config_file, dataset="UNDEFINED") with pytest.raises(KeyError): assert utils.config_loader(config_file=config_file, dataset="UNDEFINED")
def test_existing_empty_config_file(self): """ on a user defined empty mss_settings_json this test should return the default value for num_labels """ create_mss_settings_file('{ }') if not fs.open_fs(MSS_CONFIG_PATH).exists("mss_settings.json"): pytest.skip('undefined test mss_settings.json') with fs.open_fs(MSS_CONFIG_PATH) as file_dir: file_content = file_dir.readtext("mss_settings.json") assert ":" not in file_content default_data = config_loader(default=True) config_file = fs.path.combine(MSS_CONFIG_PATH, "mss_settings.json") read_config_file(path=config_file) data = config_loader() assert data["num_labels"] == default_data["num_labels"] num_labels = config_loader(dataset="num_labels") assert num_labels == default_data["num_labels"] with pytest.raises(KeyError): config_loader(dataset="UNDEFINED") with pytest.raises(KeyError): assert config_loader(dataset="UNDEFINED")
def test_existing_config_file_invalid_parameters(self): """ on a user defined mss_settings_json with duplicate and empty keys should raise FatalUserError """ create_mss_settings_file( '{"num_interpolation_points": 201, "num_interpolation_points": 10 }' ) if not fs.open_fs(MSS_CONFIG_PATH).exists("mss_settings.json"): pytest.skip('undefined test mss_settings.json') with fs.open_fs(MSS_CONFIG_PATH) as file_dir: file_content = file_dir.readtext("mss_settings.json") assert "num_interpolation_points" in file_content config_file = fs.path.combine(MSS_CONFIG_PATH, "mss_settings.json") with pytest.raises(utils.FatalUserError): read_config_file(path=config_file) create_mss_settings_file('{"": 201, "num_labels": 10 }') if not fs.open_fs(MSS_CONFIG_PATH).exists("mss_settings.json"): pytest.skip('undefined test mss_settings.json') with fs.open_fs(MSS_CONFIG_PATH) as file_dir: file_content = file_dir.readtext("mss_settings.json") assert "num_labels" in file_content with pytest.raises(utils.FatalUserError): read_config_file(path=config_file)