Repository: IAMconsortium/nomenclature

Issue:
One of multiple allowed units not passing validation
As just reported by @EmiFej, nomenclature scenario-validation currently fails if multiple units are allowed.

Error message:
```
 - 'Primary Energy|Coal' - expected: one of '['EJ/yr', 'GWh/yr']', found: 'GWh/yr'
```

FYI @phackstock @dc-almeida 


Discussion:
danielhuppmann: No idea why there was no test and why the submissions started failing now...

Due to some (weirdly) failing test, I noticed that the check "illegal characters in common definitions" was actually now testing for characters that were sanitized out of common-definition - so I added a quickfix for that (using a character that appears there) on top of the unit-quickfix.
danielhuppmann: Thanks for the suggestion, implemented your changes.

Patch:
diff --git a/nomenclature/codelist.py b/nomenclature/codelist.py
index 685bb48..0283487 100644
--- a/nomenclature/codelist.py
+++ b/nomenclature/codelist.py
@@ -622,7 +622,7 @@ class VariableCodeList(CodeList):
             (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 ''}"


Test patch:
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 76c519b..70e238e 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 1a8a1ad..fa724a3 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 a4f95ea..51b9acf 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"""