Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dc-almeida committed Oct 31, 2024
1 parent 777a2c5 commit b284d31
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
3 changes: 3 additions & 0 deletions tests/data/cli/structure_validation/nomenclature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dimensions:
- region
- variable
60 changes: 52 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,15 @@ def test_cli_run_workflow(tmp_path, simple_df):


@pytest.mark.parametrize(
"status, unit, exit_code", [("valid", "EJ/yr", 0), ("invalid", "EJ", 1)]
"status, unit, dimensions, exit_code",
[
("valid_1", "EJ/yr", "region", 0),
("invalid", "EJ", "variable", 1),
("valid_2", "EJ", "region", 0),
],
)
def test_cli_valid_scenarios(status, unit, exit_code, tmp_path):
"""Check that CLI validates an IAMC dataset according to defined codelist."""
def test_cli_valid_scenarios(status, unit, exit_code, dimensions, tmp_path):
"""Check that CLI validates an IAMC dataset according to defined codelists."""
IamDataFrame(
pd.DataFrame(
[
Expand All @@ -441,11 +446,50 @@ def test_cli_valid_scenarios(status, unit, exit_code, tmp_path):
"validate-scenarios",
str(tmp_path / f"{status}_data.xlsx"),
"--definitions",
str(
MODULE_TEST_DATA_DIR
/ "structure_validation_no_mappings"
/ "definitions"
),
str(MODULE_TEST_DATA_DIR / "structure_validation" / "definitions"),
"--dimension",
dimensions,
],
)
assert result_valid.exit_code == exit_code


@pytest.mark.parametrize(
"dimensions_src, path, unit, exit_code",
[
(
"nomenclature_yaml_dimensions",
"structure_validation",
"EJ/yr",
0,
), # defaults to nomenclature.yaml dimensions
(
"subfolders_dimensions",
"structure_validation_no_mappings",
"EJ",
1,
), # defaults to 'definitions' subfolders dimensions
],
)
def test_cli_valid_scenarios_implicit_dimensions(
dimensions_src, path, unit, exit_code, tmp_path
):
"""Check that CLI validates an IAMC dataset according to implicit dimensions codelists."""
IamDataFrame(
pd.DataFrame(
[
["m_a", "s_a", "World", "Primary Energy", unit, 1, 2],
],
columns=IAMC_IDX + [2005, 2010],
)
).to_excel(tmp_path / f"{dimensions_src}_data.xlsx")
result_valid = runner.invoke(
cli,
[
"validate-scenarios",
str(tmp_path / f"{dimensions_src}_data.xlsx"),
"--definitions",
str(MODULE_TEST_DATA_DIR / path / "definitions"),
],
)
assert result_valid.exit_code == exit_code

0 comments on commit b284d31

Please sign in to comment.