diff --git a/definitions/variable/sdg-indicators/sdg.yaml b/definitions/variable/sdg-indicators/sdg.yaml index 31fdd96e..4621c50b 100644 --- a/definitions/variable/sdg-indicators/sdg.yaml +++ b/definitions/variable/sdg-indicators/sdg.yaml @@ -98,12 +98,12 @@ sdg: 2 unit: kcal/cap/day weight: Population -- Price|Agriculture|Livestock|Index: +- Price|Agriculture|Livestock [Index]: description: Weighted average price index of livestock sdg: 2 unit: Index (2020 = 1) skip-region-aggregation: true -# weight: Agricultural Production|Non-Energy + shape: Price|Agriculture|Livestock|Index - Health|Premature Deaths|PM2.5: description: Number of premature deaths associated with increased health risks from exposure to air pollution of fine particles with a diameter of 2.5 μm or less (PM2.5) diff --git a/tests/test_legacy.py b/tests/test_legacy.py index 5c458e90..eecb39cd 100644 --- a/tests/test_legacy.py +++ b/tests/test_legacy.py @@ -1,5 +1,7 @@ from nomenclature import DataStructureDefinition +LEGACY_PROJECTS = ["navigate", "engage", "shape"] + def test_legacy_variables(): # Check that (new) variables are not referenced as deprecated legacy variables @@ -8,7 +10,7 @@ def test_legacy_variables(): legacy_variables = {} for code, attrs in dsd.variable.items(): - for project in ["navigate", "engage"]: + for project in LEGACY_PROJECTS: if project in attrs.extra_attributes: legacy_var = attrs.__getattr__(project) if legacy_var in existing_variables: diff --git a/tests/test_reserved_terms.py b/tests/test_reserved_terms.py new file mode 100644 index 00000000..f2c26759 --- /dev/null +++ b/tests/test_reserved_terms.py @@ -0,0 +1,23 @@ +from nomenclature import DataStructureDefinition + +RESERVED_TERMS = ["Index", "Share", "Value", "Volume"] + + +# TODO: Move this test to the nomenclature `validate-project` utility +# see https://github.com/IAMconsortium/nomenclature/issues/341 + + +def test_variable_ops_as_square_brackets(): + # Check that variables use square brackets for operations + # https://github.com/IAMconsortium/common-definitions/issues/55 + + dsd = DataStructureDefinition("definitions/", dimensions=["variable"]) + + error = [] + for variable in dsd.variable: + if reserved_terms := [r for r in RESERVED_TERMS if "|" + r in variable]: + error.append(f"Variable '{variable}' -> '... [{''.join(reserved_terms)}]'") + if error: + raise ValueError( + f"Found reserved terms in the following variables:\n{'\n - '.join(error)}" + )