Skip to content

Commit

Permalink
Add a test for unexpected failing of validation with multiple units (#…
Browse files Browse the repository at this point in the history
…442)

Co-authored-by: Philip Hackstock <20710924+phackstock@users.noreply.github.com>
  • Loading branch information
danielhuppmann and phackstock authored Dec 19, 2024
1 parent 4e059f8 commit e2c3484
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
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

0 comments on commit e2c3484

Please sign in to comment.