-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3615: Validate RTW user config file
- Loading branch information
1 parent
518c1fc
commit 5d262ef
Showing
5 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...ltool/utils/recipe_test_workflow/recipe_test_workflow/app/configure/bin/test_configure.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import pytest | ||
from bin.configure import validate_user_config_file | ||
from esmvalcore.config._config_validators import ValidationError | ||
|
||
|
||
def test_validate_user_config_file(): | ||
mock_valid_config = { | ||
"output_dir": "~/esmvaltool_output", | ||
"auxiliary_data_dir": "~/auxiliary_data", | ||
"search_esgf": "never", | ||
"download_dir": "~/climate_data", | ||
"max_parallel_tasks": None, | ||
"log_level": "info", | ||
"exit_on_warning": True, | ||
"output_file_type": "png", | ||
} | ||
# No assert statement is needed. If the function call errors Pytest | ||
# considers the test failed. | ||
validate_user_config_file(mock_valid_config) | ||
|
||
|
||
def test_validate_user_config_file_one_validation_error(): | ||
mock_one_invalid_config = { | ||
"output_dir": "~/esmvaltool_output", | ||
"auxiliary_data_dir": "~/auxiliary_data", | ||
"search_esgf": "never", | ||
"download_dir": "~/climate_data", | ||
"max_parallel_tasks": None, | ||
"log_level": "info", | ||
"exit_on_warning": 100, | ||
"output_file_type": "png", | ||
} | ||
with pytest.raises( | ||
ValidationError, | ||
match='Validation error for EXIT_ON_WARNING with value "100"\n' | ||
'ERROR: Could not convert `100` to `bool`\n'): | ||
validate_user_config_file(mock_one_invalid_config) | ||
|
||
|
||
def test_validate_user_config_file_two_validation_errors(): | ||
mock_two_invalids_config = { | ||
"output_dir": 111, | ||
"auxiliary_data_dir": "~/auxiliary_data", | ||
"search_esgf": "never", | ||
"download_dir": "~/climate_data", | ||
"max_parallel_tasks": None, | ||
"log_level": "info", | ||
"exit_on_warning": 100, | ||
"output_file_type": "png", | ||
} | ||
with pytest.raises( | ||
ValidationError, | ||
match='Validation error for OUTPUT_DIR with value "111"\nERROR: ' | ||
'Expected a path, but got 111\n\nValidation error for ' | ||
'EXIT_ON_WARNING with value "100"\nERROR: Could not convert `100` ' | ||
'to `bool`\n'): | ||
validate_user_config_file(mock_two_invalids_config) | ||
|
||
|
||
def test_validate_user_config_file_key_error(): | ||
mock_one_key_error = { | ||
"output_dir": "~/esmvaltool_output", | ||
"auxiliary_data_dir": "~/auxiliary_data", | ||
"search_esgf": "never", | ||
"download_dir": "~/climate_data", | ||
"one_rogue_field": 90210, | ||
"max_parallel_tasks": None, | ||
"log_level": "info", | ||
"exit_on_warning": True, | ||
"output_file_type": "png", | ||
} | ||
with pytest.raises( | ||
ValidationError, | ||
match="Key Error for ONE_ROGUE_FIELD. May not be a valid " | ||
"ESMValTool user configuration key\nERROR: 'one_rogue_field'\n"): | ||
validate_user_config_file(mock_one_key_error) |