Skip to content

Commit

Permalink
Update stray tag tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-almeida committed Oct 9, 2024
1 parent 780198e commit f7620d5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
13 changes: 13 additions & 0 deletions tests/data/codelist/stray_tag/char_in_dict/variables.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- Primary Energy:
definition: Total primary energy consumption
unit: EJ/yr
info:
valid: Valid information.
invalid: Invalid bracket } information.
final: Another valid information.
- Primary Energy|Coal:
definition: Primary energy consumption of coal
unit: EJ/yr
- Share|Coal:
definition: Share of coal in the total primary energy mix
unit: EJ/yr
14 changes: 14 additions & 0 deletions tests/data/codelist/stray_tag/char_in_list/variables.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- Primary Energy:
definition: Total primary energy consumption
unit: EJ/yr
- Primary Energy|Coal:
definition: Primary energy consumption of coal
unit: EJ/yr
- Share|Coal:
definition: Share of coal in the total primary energy mix
unit: EJ/yr
info:
- Valid information.
- Invalid bracket { information.
- Another valid information.

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
unit: EJ/yr
- Share|{Fuel}:
definition: Share of {Fuel} in the total primary energy mix
unit:
unit: EJ/yr
18 changes: 15 additions & 3 deletions tests/test_codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,24 @@ def test_to_csv():


def test_stray_tag_fails():
"""Check that typos in a tag raises expected error"""
"""Check that stray brackets from, e.g. typos in a tag, raises expected error"""

match = r"Unexpected bracket in codelist: Primary Energy\|{Feul}"
with raises(ValueError, match=match):
VariableCodeList.from_directory(
"variable", MODULE_TEST_DATA_DIR / "stray_tag" / "char_in_str"
)

match = r"Unexpected bracket in codelist: Share\|Coal"
with raises(ValueError, match=match):
VariableCodeList.from_directory(
"variable", MODULE_TEST_DATA_DIR / "stray_tag" / "char_in_list"
)

match = r"Unexpected {} in codelist: Primary Energy\|{Feul}"
match = r"Unexpected bracket in codelist: Primary Energy"
with raises(ValueError, match=match):
VariableCodeList.from_directory(
"variable", MODULE_TEST_DATA_DIR / "stray_tag" / "definitions" / "variable"
"variable", MODULE_TEST_DATA_DIR / "stray_tag" / "char_in_dict"
)


Expand Down

0 comments on commit f7620d5

Please sign in to comment.