From e825e3bf5049c9035c9c72584bbe9240cfca25da Mon Sep 17 00:00:00 2001 From: pesap Date: Tue, 14 Jan 2025 17:08:07 -0700 Subject: [PATCH] Improve testing --- src/r2x/runner.py | 4 +++- tests/test_runner.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/r2x/runner.py b/src/r2x/runner.py index 6bb6981..7c62296 100644 --- a/src/r2x/runner.py +++ b/src/r2x/runner.py @@ -158,7 +158,9 @@ def run(cli_args: dict, user_dict: dict | None = None) -> None: logger.info("Running {} scenarios", len(config_mgr)) for _, scenario in config_mgr.scenarios.items(): # NOTE: We can pass multiple years from the CLI. In those cases we want to raise not implemented. - if hasattr(scenario, "solve_year") and isinstance(getattr(scenario, "solve_year"), list): + if hasattr(scenario, "input_config") and isinstance( + getattr(scenario.input_config, "solve_year"), list + ): msg = "Multi year runs from the CLI is not yet supported. Use scenarios instead." raise NotImplementedError(msg) run_single_scenario(scenario) diff --git a/tests/test_runner.py b/tests/test_runner.py index e46d383..bfa0830 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -1,3 +1,4 @@ +import pytest from r2x.runner import init, run @@ -16,6 +17,22 @@ def test_runner(tmp_path, reeds_data_folder): _ = run(cli_input, {}) +def test_runner_exceptions(tmp_path, reeds_data_folder): + cli_input = { + "name": "Test", + "weather_year": 2015, + "solve_year": [2055, 2050], + "input_model": "reeds-US", + "output_model": "sienna", + "output_folder": str(tmp_path), + "feature_flags": {"cool-feature": True}, + "run_folder": reeds_data_folder, + } + + with pytest.raises(NotImplementedError): + _ = run(cli_input, {}) + + def test_init(tmp_path): cli_input = {"path": str(tmp_path)} _ = init(cli_input)