Skip to content

Commit

Permalink
Improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pesap committed Jan 15, 2025
1 parent 4b581d6 commit e825e3b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/r2x/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from r2x.runner import init, run


Expand All @@ -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)
Expand Down

0 comments on commit e825e3b

Please sign in to comment.