Skip to content

Commit

Permalink
Test for validation error when missing units in inputs.yaml
Browse files Browse the repository at this point in the history
Confirms fix for #146020609.
  • Loading branch information
tomalrussell committed Jun 8, 2017
1 parent 84a7143 commit edea603
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion smif/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def log_validation_errors():
"""Log validation errors
"""
for error in VALIDATION_ERRORS:
LOGGER.error(error)
LOGGER.error(str(error))


def path_to_abs(relative_root, path):
Expand Down
23 changes: 23 additions & 0 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,29 @@ def test_validation_invalid(
mock_print.assert_called_with('The model configuration was invalid')


@patch('smif.cli.LOGGER.error')
@patch('builtins.print')
def test_validation_invalid_units(
mock_print,
error_logger,
setup_folder_structure,
setup_project_folder,
setup_water_inputs_missing_units):
"""Ensure invalid inputs yaml file raises error
"""
config_file = os.path.join(str(setup_folder_structure), 'config', 'model.yaml')
args = get_args(['validate', config_file])

with raises(SystemExit):
validate_config(args)

assert len(VALIDATION_ERRORS) > 0

msg_start = "Expected a value for 'units' in each model dependency"
assert msg_start in error_logger.call_args[0][0]
mock_print.assert_called_with('The model configuration was invalid')


@patch('builtins.input', return_value='y')
def test_confirm_yes(input):
assert confirm()
Expand Down
13 changes: 13 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,19 @@ def setup_water_inputs(setup_folder_structure):
filename.write(yaml_contents, ensure=True)


@fixture(scope='function')
def setup_water_inputs_missing_units(setup_folder_structure):
base_folder = setup_folder_structure
filename = base_folder.join('data', 'water_supply', 'inputs.yaml')
contents = [{
'name': 'reservoir pumpiness',
'spatial_resolution': 'LSOA',
'temporal_resolution': 'annual'
}]
yaml_contents = yaml.dump(contents)
filename.write(yaml_contents, ensure=True)


@fixture(scope='function')
def water_outputs_contents():
contents = [
Expand Down

0 comments on commit edea603

Please sign in to comment.