From 54b6608bf8d4356ddf50f6e2cc15a20a8b83bd38 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Fri, 10 Dec 2021 10:51:07 +0000 Subject: [PATCH 1/2] Add string to allowed types --- openfisca_core/parameters/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openfisca_core/parameters/config.py b/openfisca_core/parameters/config.py index e9a3041ae8..b380efa856 100644 --- a/openfisca_core/parameters/config.py +++ b/openfisca_core/parameters/config.py @@ -19,7 +19,7 @@ # 'unit' and 'reference' are only listed here for backward compatibility. # It is now recommended to include them in metadata, until a common consensus emerges. -ALLOWED_PARAM_TYPES = (float, int, bool, type(None), typing.List) +ALLOWED_PARAM_TYPES = (float, int, bool, type(None), typing.List, str) COMMON_KEYS = {'description', 'metadata', 'unit', 'reference', 'documentation'} FILE_EXTENSIONS = {'.yaml', '.yml'} From 18cd0c106524a09b5ff0af5a78be7de19855ee4f Mon Sep 17 00:00:00 2001 From: Nikhil Date: Fri, 10 Dec 2021 10:51:29 +0000 Subject: [PATCH 2/2] Add new test and remove now incorrect test --- tests/core/parameter_validation/string_parameter.yaml | 9 +++++++++ .../parameter_validation/test_parameter_validation.py | 8 +++++++- tests/core/parameter_validation/wrong_value.yaml | 3 --- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 tests/core/parameter_validation/string_parameter.yaml delete mode 100644 tests/core/parameter_validation/wrong_value.yaml diff --git a/tests/core/parameter_validation/string_parameter.yaml b/tests/core/parameter_validation/string_parameter.yaml new file mode 100644 index 0000000000..e88f5286ed --- /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 62b2b0c132..ddb7119324 100644 --- a/tests/core/parameter_validation/test_parameter_validation.py +++ b/tests/core/parameter_validation/test_parameter_validation.py @@ -23,7 +23,6 @@ def check_fails_with_message(file_name, keywords): ('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'}), - ('wrong_value', {'not one of the allowed types', 'wrong_value[2015-12-01]', '1A'}), ('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'}), @@ -58,3 +57,10 @@ def test_yaml_hierarchy(): 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" diff --git a/tests/core/parameter_validation/wrong_value.yaml b/tests/core/parameter_validation/wrong_value.yaml deleted file mode 100644 index f120c81ac7..0000000000 --- a/tests/core/parameter_validation/wrong_value.yaml +++ /dev/null @@ -1,3 +0,0 @@ -values: - 2015-12-01: - value: 1A