Skip to content

Commit

Permalink
Add explicit test for duplicate code errors
Browse files Browse the repository at this point in the history
  • Loading branch information
phackstock committed Jan 23, 2024
1 parent 1081d4a commit 31bc11c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/data/duplicate-code-list/variable/duplicate_entries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- Some Variable:
description:
unit:
- Some Variable:
description:
unit:
- Some other Variable:
description:
unit:
- Some other Variable:
description:
unit:
14 changes: 12 additions & 2 deletions tests/test_codelist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pytest import raises
import pandas as pd
import pandas.testing as pdt
import pytest
import logging

from nomenclature.code import Code, RegionCode, MetaCode
Expand Down Expand Up @@ -331,11 +332,20 @@ def test_multiple_external_repos():
TEST_DATA_DIR / "nomenclature_configs" / "multiple_repos_per_dimension.yaml"
)
try:
with raises(ValueError, match="Duplicate"):
variable_code_list = VariableCodeList.from_directory(
with raises(ValueError, match="Collected 529 errors"):
VariableCodeList.from_directory(
"variable",
TEST_DATA_DIR / "nomenclature_configs" / "variable",
nomenclature_config,
)
finally:
clean_up_external_repos(nomenclature_config.repositories)


@pytest.mark.parametrize("CodeList", [VariableCodeList, CodeList])
def test_variable_codelist_with_duplicates_raises(CodeList):
error_string = "2 errors:\n.*Some Variable\n.*Some other Variable"
with raises(ValueError, match=error_string):
CodeList.from_directory(
"variable", TEST_DATA_DIR / "duplicate-code-list" / "variable"
)

0 comments on commit 31bc11c

Please sign in to comment.