Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phackstock committed Dec 20, 2023
1 parent 6884626 commit 4c76173
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion tests/test_codelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
RegionCodeList,
MetaCodeList,
)
from nomenclature.error import pydantic_custom_errors
from nomenclature.error import custom_pydantic_errors

from conftest import TEST_DATA_DIR

Expand Down
16 changes: 5 additions & 11 deletions tests/test_region_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RegionProcessor,
process,
)
from nomenclature.error import pydantic_custom_errors
from nomenclature.error import custom_pydantic_errors
from nomenclature.processor.region import NativeRegion, CommonRegion
from pyam import IamDataFrame, assert_iamframe_equal
from pyam.utils import IAMC_IDX
Expand Down Expand Up @@ -145,17 +145,11 @@ def test_region_processor_not_defined(simple_definition):
# definition
error_msg = (
"mappings.model_(a|b).*\n"
".*region_a.*mapping_(1|2).yaml.*value_error.*\n"
".*\n"
".*region_a.*mapping_(1|2).yaml.*region_not_defined.*\n"
"mappings.model_(a|b).*\n"
".*region_a.*mapping_(1|2).yaml.*value_error"
".*region_a.*mapping_(1|2).yaml.*region_not_defined"
)
try:
RegionProcessor.from_directory(
TEST_DATA_DIR / "regionprocessor_not_defined", simple_definition
)
except pydantic.ValidationError as error:
pass

with pytest.raises(ValueError, match=error_msg):
RegionProcessor.from_directory(
TEST_DATA_DIR / "regionprocessor_not_defined", simple_definition
Expand All @@ -175,7 +169,7 @@ def test_region_processor_wrong_args():

# Test with an integer
with pytest.raises(pydantic.ValidationError, match=".*path\n.*not a valid path.*"):
RegionProcessor.from_directory(123)
RegionProcessor.from_directory(path=123)

# Test with a file, a path pointing to a directory is required
with pytest.raises(
Expand Down
34 changes: 18 additions & 16 deletions tests/test_required_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,32 @@
from pyam import assert_iamframe_equal
from nomenclature import DataStructureDefinition, RequiredDataValidator
from nomenclature.processor.required_data import RequiredMeasurand
from nomenclature.error import pydantic_custom_errors
from nomenclature.error import custom_pydantic_errors

REQUIRED_DATA_TEST_DIR = TEST_DATA_DIR / "required_data" / "required_data"


def test_RequiredDataValidator_from_file():
exp = {
"description": "Required variables for running MAGICC",
"model": ["model_a"],
"required_data": [
{
"measurand": [
RequiredMeasurand(variable="Emissions|CO2", unit="Mt CO2/yr")
],
"region": ["World"],
"year": [2020, 2030, 2040, 2050],
},
],
"file": REQUIRED_DATA_TEST_DIR / "requiredData.yaml",
}
exp = RequiredDataValidator(
**{
"description": "Required variables for running MAGICC",
"model": ["model_a"],
"required_data": [
{
"measurand": [
RequiredMeasurand(variable="Emissions|CO2", unit="Mt CO2/yr")
],
"region": ["World"],
"year": [2020, 2030, 2040, 2050],
},
],
"file": REQUIRED_DATA_TEST_DIR / "requiredData.yaml",
}
)

obs = RequiredDataValidator.from_file(REQUIRED_DATA_TEST_DIR / "requiredData.yaml")

assert obs.model_dump(exclude_unset=True) == exp
assert obs == exp


def test_RequiredDataValidator_validate_with_definition():
Expand Down

0 comments on commit 4c76173

Please sign in to comment.