From 22dfd6d1f7e816ecfe79213495426c6322e8026a Mon Sep 17 00:00:00 2001 From: pesap Date: Tue, 3 Dec 2024 13:29:50 -0700 Subject: [PATCH] test: Adding coverage for `get_config` --- tests/test_configuration_class.py | 87 ++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/tests/test_configuration_class.py b/tests/test_configuration_class.py index 371020a2..bc64aa31 100644 --- a/tests/test_configuration_class.py +++ b/tests/test_configuration_class.py @@ -1,7 +1,7 @@ """Testing for the configuration and Scenario class.""" import pytest -from r2x.config import Scenario, Configuration +from r2x.config import Scenario, Configuration, get_config from r2x.utils import read_fmap @@ -80,6 +80,91 @@ def test_config_from_cli(): assert len(scenario_mgr) == 1 +def test_config_from_scenarios(): + user_dict = { + "input_model": "reeds-US", + "output_model": "sienna", + "scenarios": [ + { + "name": "test2030", + "weather_year": 2015, + "solve_year": 2030, + }, + { + "name": "test2050", + "weather_year": 2015, + "solve_year": 2055, + }, + ], + } + + config = Configuration.from_scenarios({}, user_dict) + assert config is not None + assert len(config) == 2 + assert config["test2030"] + assert config["test2030"].solve_year == 2030 + + +@pytest.mark.parametrize( + "cli_input,user_dict", + [ + ( + { + "name": "Test", + "weather_year": 2015, + "solve_year": [2055], + "input_model": "plexos", + "output_model": "sienna", + }, + {}, + ), + ( + {}, + { + "input_model": "reeds-US", + "output_model": "sienna", + "scenarios": [ + { + "name": "test2030", + "weather_year": 2015, + "solve_year": 2030, + }, + { + "name": "test2050", + "weather_year": 2015, + "solve_year": 2055, + }, + ], + }, + ), + ( + { + "name": "Test", + "weather_year": 2015, + "input_model": "plexos", + "output_model": "sienna", + }, + { + "scenarios": [ + { + "name": "test2030", + "solve_year": 2030, + }, + { + "name": "test2050", + "solve_year": 2055, + }, + ], + }, + ), + ], + ids=["no-user-dict", "no-cli", "both"], +) +def test_get_config(cli_input, user_dict): + config = get_config(cli_input, user_dict) + assert config is not None + + def test_config_override(scenario_instance): user_dict = {"fmap": {"xml_file": {"fname": "test_override"}}} cli_args = {"output_model": "sienna"}