Skip to content

Commit

Permalink
test: Adding coverage for get_config
Browse files Browse the repository at this point in the history
  • Loading branch information
pesap committed Dec 3, 2024
1 parent f894fd2 commit 22dfd6d
Showing 1 changed file with 86 additions and 1 deletion.
87 changes: 86 additions & 1 deletion tests/test_configuration_class.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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"}
Expand Down

0 comments on commit 22dfd6d

Please sign in to comment.