diff --git a/nomenclature/codelist.py b/nomenclature/codelist.py index 685bb483..0283487f 100644 --- a/nomenclature/codelist.py +++ b/nomenclature/codelist.py @@ -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 ''}" diff --git a/tests/data/codelist/illegal_chars/char_in_external_repo/nomenclature.yaml b/tests/data/codelist/illegal_chars/char_in_external_repo/nomenclature.yaml index 76c519bf..70e238e4 100644 --- a/tests/data/codelist/illegal_chars/char_in_external_repo/nomenclature.yaml +++ b/tests/data/codelist/illegal_chars/char_in_external_repo/nomenclature.yaml @@ -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 diff --git a/tests/data/data_structure_definition/extras_nc/variable/variables.yaml b/tests/data/data_structure_definition/extras_nc/variable/variables.yaml index 1a8a1ad4..fa724a38 100644 --- a/tests/data/data_structure_definition/extras_nc/variable/variables.yaml +++ b/tests/data/data_structure_definition/extras_nc/variable/variables.yaml @@ -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 diff --git a/tests/test_validation.py b/tests/test_validation.py index a4f95ea3..51b9acf3 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -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"""