def test_missing_planning(get_sos_model_config): """Expect an error if missing planning """ data = get_sos_model_config del data['planning'] validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "No 'planning' mode specified in main config" assert msg in str(ex)
def test_sector_models_empty_list(get_sos_model_config): """Expect an error if sector_models is an empty list """ data = get_sos_model_config data['sector_models'] = [] validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "No 'sector_models' specified in main config" assert msg in str(ex)
def test_sector_model_type(get_sos_model_config): """Expect an error if sector_model config is not a dict """ data = get_sos_model_config data['sector_models'] = [None] validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "Expected a sector model config block" assert msg in str(ex)
def test_missing_sector_models(get_sos_model_config): """Expect an error if missing sector_models """ data = get_sos_model_config del data['sector_models'] validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "No 'sector_models' specified in main config" assert msg in str(ex)
def test_used_planning_needs_files(get_sos_model_config): """Expect an error if a planning mode is to be used, but has no files """ data = get_sos_model_config del data["planning"]["pre_specified"]["files"] validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "No 'files' provided for the 'pre_specified' planning type in main config" assert msg in str(ex)
def test_invalid_timesteps_file(get_sos_model_config): """Expect an error if timesteps is not a path to a file """ data = get_sos_model_config data['timesteps'] = 3 validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "Expected 'timesteps' in main config to specify a timesteps file, instead got 3" assert msg in str(ex)
def test_modelrun_config_invalid(): """Expect an error if not a dict """ invalid_possibilities = [0, [], "just a string", 3.1415] for invalid_data in invalid_possibilities: validate_sos_model_config(invalid_data) ex = VALIDATION_ERRORS.pop() msg = "Main config file should contain setup data" assert msg in str(ex)
def test_sector_models_not_list(get_sos_model_config): """Expect an error if sector_models is not a list """ data = get_sos_model_config data['sector_models'] = 42 validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "Expected 'sector_models' in main config to specify a list of sector " + \ "models to run, instead got 42." assert msg in str(ex)
def test_scenario_data_missing(self, get_sos_model_config): """Expect an error if no scenario data is specified, but referenced in input file """ data = get_sos_model_config del data['scenario_data'] validate_sos_model_config(data) ex = VALIDATION_ERRORS.pop() msg = "No 'scenario_data' specified in main config file." assert msg == str(ex)
def test_planning_missing_required(get_sos_model_config): """Expect an error if missing a planning mode """ required_keys = ["pre_specified", "rule_based", "optimisation"] for key in required_keys: data = get_sos_model_config["planning"] del data[key] validate_planning_config(data) ex = VALIDATION_ERRORS.pop() msg = "No '{}' settings specified under 'planning'".format(key) assert msg in str(ex)
def test_time_interval_required(get_time_intervals): """Expect an error if a set of time_intervals is not a list """ required_keys = ['id', 'start', 'end'] for key in required_keys: data = get_time_intervals del data[0][key] validate_time_intervals(data, '/path/to/interval_set.yaml') ex = VALIDATION_ERRORS.pop() msg = "Expected a value for '{}' in each time interval".format(key) assert msg in str(ex)
def test_sector_model_required(get_sector_model_initial_config): """Expect an error if a sector_model is missing a required key """ required_keys = ['name', 'config_dir', 'path', 'classname'] for key in required_keys: data = get_sector_model_initial_config del data[key] validate_sector_model_initial_config(data) ex = VALIDATION_ERRORS.pop() msg = "Expected a value for '{}'".format(key) assert msg in str(ex)
def test_dependency_required(get_dependency): """Expect an error if dependency is missing required fields """ required_keys = [ 'name', 'spatial_resolution', 'temporal_resolution', 'units' ] for key in required_keys: data = get_dependency del data[key] validate_dependency(data) ex = VALIDATION_ERRORS.pop() msg = "Expected a value for '{}' in each model dependency, " + \ "only received {}" assert msg.format(key, data) in str(ex)
def test_interventions_checks_for_units(get_intervention): """Expect an error if an intervention's "capacity" has no units """ intervention = get_intervention intervention["capacity"] = 3 data = [intervention] msg = "Loading interventions from /path/to/data.yaml, asset.capacity " + \ "was 3 but should have specified units, e.g. " + \ "{'value': 3, 'units': 'm'}" validate_interventions(data, "/path/to/data.yaml") ex = VALIDATION_ERRORS.pop() assert msg in str(ex)
def test_scenario_missing_required(get_scenario_data): """Expect an error if a scenario datum is missing required key """ required_keys = ["region", "interval", "year", "value"] for key in required_keys: data = get_scenario_data for obs in data: del obs[key] msg = "Expected a value for '{}' in each data point in a scenario".format( key) validate_scenario_data(data, "/path/to/data.yaml") ex = VALIDATION_ERRORS.pop() assert msg in str(ex)
def test_scenario_config_missing_required(get_sos_model_config): """Expect an error if a scenario datum is missing required key """ required_keys = [ "parameter", "spatial_resolution", "temporal_resolution", "units", "file" ] for key in required_keys: data = get_sos_model_config['scenario_data'][0] del data[key] msg = "Expected a value for '{}' in each scenario".format(key) validate_scenario(data) ex = VALIDATION_ERRORS.pop() assert msg in str(ex)
def test_interventions_missing_required(get_intervention): """Expect an error if an intervention is missing required key """ required_keys = [ "name", "location", "capital_cost", "operational_lifetime", "economic_lifetime" ] for key in required_keys: intervention = get_intervention del intervention[key] data = [intervention] msg = "required a value for '{}' in each intervention".format(key) validate_interventions(data, "/path/to/data.yaml") ex = VALIDATION_ERRORS.pop() assert msg in str(ex)