diff --git a/nomenclature/cli.py b/nomenclature/cli.py index 52103201..1a0f45e5 100644 --- a/nomenclature/cli.py +++ b/nomenclature/cli.py @@ -9,7 +9,6 @@ from nomenclature.definition import DataStructureDefinition from nomenclature.codelist import VariableCodeList from nomenclature.processor import RegionProcessor -from nomenclature.config import NomenclatureConfig from nomenclature.testing import assert_valid_structure, assert_valid_yaml cli = click.Group() @@ -321,13 +320,4 @@ def cli_validate_scenarios(input_file: Path, definitions: Path, dimensions: List ValueError If input_file validation fails against specified codelist(s). """ - if not dimensions: # if "dimensions" were not specified - if definitions.parent / "nomenclature.yaml" in definitions.parent.iterdir(): - dimensions = NomenclatureConfig.from_file( - definitions.parent / "nomenclature.yaml" - ).dimensions - if not dimensions: - dimensions = [x.stem for x in definitions.iterdir() if x.is_dir()] - if not dimensions: - raise FileNotFoundError(f"`definitions` directory is empty: {definitions}") DataStructureDefinition(definitions, dimensions).validate(IamDataFrame(input_file)) diff --git a/tests/data/cli/structure_validation/nomenclature.yaml b/tests/data/cli/structure_validation/nomenclature.yaml index 78ee58e7..83535f55 100644 --- a/tests/data/cli/structure_validation/nomenclature.yaml +++ b/tests/data/cli/structure_validation/nomenclature.yaml @@ -1,3 +1,3 @@ dimensions: - region - - variable \ No newline at end of file + - variable diff --git a/tests/test_cli.py b/tests/test_cli.py index c86a40b4..ce698579 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -425,7 +425,7 @@ def test_cli_run_workflow(tmp_path, simple_df): @pytest.mark.parametrize( "status, unit, dimensions, exit_code", [ - ("valid_1", "EJ/yr", "region", 0), + ("valid_1", "EJ/yr", ["region", "variable"], 0), ("invalid", "EJ", "variable", 1), ("valid_2", "EJ", "region", 0), ], @@ -440,6 +440,12 @@ def test_cli_valid_scenarios(status, unit, exit_code, dimensions, tmp_path): columns=IAMC_IDX + [2005, 2010], ) ).to_excel(tmp_path / f"{status}_data.xlsx") + dimensions = [dimensions] if isinstance(dimensions, str) else dimensions + dimension_args = [] + for dim in dimensions: + dimension_args.append("--dimension") + dimension_args.append(dim) + result_valid = runner.invoke( cli, [ @@ -447,49 +453,29 @@ def test_cli_valid_scenarios(status, unit, exit_code, dimensions, tmp_path): str(tmp_path / f"{status}_data.xlsx"), "--definitions", str(MODULE_TEST_DATA_DIR / "structure_validation" / "definitions"), - "--dimension", - dimensions, - ], + ] + + dimension_args, ) 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 -): +def test_cli_valid_scenarios_implicit_dimensions(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], + ["m_a", "s_a", "World", "Primary Energy", "EJ/yr", 1, 2], ], columns=IAMC_IDX + [2005, 2010], ) - ).to_excel(tmp_path / f"{dimensions_src}_data.xlsx") + ).to_excel(tmp_path / "valid_data.xlsx") result_valid = runner.invoke( cli, [ "validate-scenarios", - str(tmp_path / f"{dimensions_src}_data.xlsx"), + str(tmp_path / "valid_data.xlsx"), "--definitions", - str(MODULE_TEST_DATA_DIR / path / "definitions"), + str(MODULE_TEST_DATA_DIR / "structure_validation" / "definitions"), ], ) - assert result_valid.exit_code == exit_code + assert result_valid.exit_code == 0