Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for unexpected failing of validation with multiple units #442

Merged
merged 5 commits into from
Dec 19, 2024
Merged
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 nomenclature/codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ def validate_units(
(variable, unit, self.mapping[variable].unit)
for variable, unit in unit_mapping.items()
if variable in self.variables
and not set(unit) == set(self.mapping[variable].unit)
and unit not in self.mapping[variable].units
]:
lst = [
f"'{v}' - expected: {'one of ' if isinstance(e, list) else ''}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ definitions:
repository:
- common-definitions
check_illegal_characters: true
illegal_characters: ['"' , ";"] # these are known to be present in common-definitions variables
illegal_characters: ["'"] # these are known to be present in common-definitions variables
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
unit: EJ/yr
- Primary Energy|Coal:
definition: Primary energy consumption of coal
unit: EJ/yr
unit: [EJ/yr, GWh/yr]
- Variable (w/ bunkers):
definition: This is a variable with special characters for testing purposes
unit: EJ/yr
9 changes: 9 additions & 0 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def test_validation_fails_region(simple_definition, simple_df, caplog):
)


def test_validation_multiple_units(extras_definition, simple_df):
"""Validating against a VariableCode with multiple units works as expected"""
extras_definition.validate(
simple_df
.filter(variable="Primary Energy|Coal")
.rename(unit={"EJ/yr": "GWh/yr"})
)


def test_validation_with_custom_dimension(simple_df):
"""Check validation with a custom DataStructureDefinition dimension"""

Expand Down
Loading