Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openfisca_core/parameters/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}

Expand Down
9 changes: 9 additions & 0 deletions tests/core/parameter_validation/string_parameter.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion tests/core/parameter_validation/test_parameter_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}),
Expand Down Expand Up @@ -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"
3 changes: 0 additions & 3 deletions tests/core/parameter_validation/wrong_value.yaml

This file was deleted.