diff --git a/tests/core/parameter_validation/string_parameter.yaml b/tests/core/parameter_validation/string_parameter.yaml new file mode 100644 index 000000000..e88f5286e --- /dev/null +++ b/tests/core/parameter_validation/string_parameter.yaml @@ -0,0 +1,9 @@ +description: A parameter with a string value +values: + 2015-01-01: string, without metadata + 2016-01-01: + value: string, with metadata + metadata: + unit: string + period: year + reference: none provided diff --git a/tests/core/parameter_validation/test_parameter_validation.py b/tests/core/parameter_validation/test_parameter_validation.py index db4b74234..501f55861 100644 --- a/tests/core/parameter_validation/test_parameter_validation.py +++ b/tests/core/parameter_validation/test_parameter_validation.py @@ -23,43 +23,23 @@ def check_fails_with_message(file_name, keywords) -> None: raise -@pytest.mark.parametrize( - "test", - [ - ( - "indentation", - { - "Invalid YAML", - "indentation.yaml", - "line 2", - "mapping values are not allowed", - }, - ), - ( - "wrong_date", - { - "Error parsing parameter file", - "Properties must be valid YYYY-MM-DD instants", - }, - ), - ("wrong_scale", {"Unexpected property", "scale[1]", "treshold"}), - ("unexpected_key_in_parameter", {"Unexpected property", "unexpected_key"}), - ("wrong_type_in_parameter", {"must be of type object"}), - ("wrong_type_in_value_history", {"must be of type object"}), - ("unexpected_key_in_value_history", {"must be valid YYYY-MM-DD instants"}), - ( - "unexpected_key_in_value_at_instant", - {"Unexpected property", "unexpected_key"}, - ), - ("unexpected_key_in_scale", {"Unexpected property", "unexpected_key"}), - ("wrong_type_in_scale", {"must be of type object"}), - ("wrong_type_in_brackets", {"must be of type array"}), - ("wrong_type_in_bracket", {"must be of type object"}), - ("missing_value", {"missing", "value"}), - ("duplicate_key", {"duplicate"}), - ], -) -def test_parsing_errors(test) -> None: +@pytest.mark.parametrize("test", [ + ('indentation', {'Invalid YAML', 'indentation.yaml', 'line 2', 'mapping values are not allowed'}), + ("wrong_date", {"Error parsing parameter file", "Properties must be valid YYYY-MM-DD instants"}), + ('wrong_scale', {'Unexpected property', 'scale[1]', 'treshold'}), + ('unexpected_key_in_parameter', {'Unexpected property', 'unexpected_key'}), + ('wrong_type_in_parameter', {'must be of type object'}), + ('wrong_type_in_value_history', {'must be of type object'}), + ('unexpected_key_in_value_history', {'must be valid YYYY-MM-DD instants'}), + ('unexpected_key_in_value_at_instant', {'Unexpected property', 'unexpected_key'}), + ('unexpected_key_in_scale', {'Unexpected property', 'unexpected_key'}), + ('wrong_type_in_scale', {'must be of type object'}), + ('wrong_type_in_brackets', {'must be of type array'}), + ('wrong_type_in_bracket', {'must be of type object'}), + ('missing_value', {'missing', 'value'}), + ('duplicate_key', {'duplicate'}), + ]) +def test_parsing_errors(test): with pytest.raises(ParameterParsingError): check_fails_with_message(*test) @@ -81,3 +61,10 @@ def test_yaml_hierarchy() -> None: parameters = ParameterNode("", directory_path=path) parameters_at_instant = parameters("2016-01-01") assert parameters_at_instant.node1.param == 1.0 + + +def test_string_parameter(): + path = os.path.join(BASE_DIR, 'string_parameter.yaml') + parameter = load_parameter_file(path, 'string_parameter') + assert parameter("2015-01-01") == "string, without metadata" + assert parameter("2016-01-01") == "string, with metadata"