Skip to content

Commit 21084b7

Browse files
committed
Add more test stubs of .material…run_reporting
1 parent 58e3734 commit 21084b7

File tree

2 files changed

+97
-4
lines changed

2 files changed

+97
-4
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from itertools import product
2+
3+
import pandas as pd
4+
import pyam
5+
6+
from message_ix_models.model.material.report.reporting import convert_mass_to_energy
7+
8+
_t = ["CH2O_synth", "MTO_petro"]
9+
_ltm = list(
10+
product(
11+
["primary", "primary_material"],
12+
["bio", "bio_ccs", "coal", "coal_ccs", "h2", "ng", "ng_ccs"],
13+
["feedstock", "fuel"],
14+
)
15+
)
16+
#: List of variables expected by convert_mass_to_energy()
17+
VARIABLE = [f"in|final_material|methanol|{t}|M1" for t in _t] + [
18+
f"out|{l_}|methanol|meth_{t}|{m}" for l_, t, m in _ltm
19+
]
20+
21+
22+
def test_convert_mass_to_energy() -> None:
23+
df = pd.DataFrame([[v, 1.0] for v in VARIABLE], columns=["variable", 1]).assign(
24+
model="m", scenario="s", region="r", unit="u"
25+
)
26+
idf = pyam.IamDataFrame(df)
27+
28+
# Function runs without error
29+
result = convert_mass_to_energy(idf)
30+
31+
# TODO Add assertions
32+
del result

message_ix_models/tests/model/material/test_run_reporting.py

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,34 @@
1+
import pandas as pd
2+
import pyam
13
import pytest
4+
from message_ix import Reporter, Scenario
25
from pytest import param
36

4-
from message_ix_models.model.material.report.run_reporting import load_config, run
5-
from message_ix_models.tests.test_tools import scenario # noqa: F401
7+
from message_ix_models import Context
8+
from message_ix_models.model.material.report.run_reporting import (
9+
load_config,
10+
run,
11+
run_ch4_reporting,
12+
run_fe_methanol_nh3_reporting,
13+
run_fe_reporting,
14+
run_fs_reporting,
15+
run_prod_reporting,
16+
split_fe_other,
17+
)
18+
from message_ix_models.testing import bare_res
19+
20+
MARK = pytest.mark.xfail(reason="Fixture scenario does not have materials contents")
21+
22+
23+
@pytest.fixture
24+
def reporter(scenario) -> Reporter:
25+
return Reporter.from_scenario(scenario)
26+
27+
28+
@pytest.fixture
29+
def scenario(request: pytest.FixtureRequest, test_context: Context) -> Scenario:
30+
test_context.model.regions = "R12"
31+
return bare_res(request, test_context, solved=False)
632

733

834
@pytest.mark.parametrize(
@@ -28,7 +54,42 @@ def test_load_config(config_name, exp_len) -> None:
2854
# TODO Extend assertions
2955

3056

31-
@pytest.mark.xfail(reason="Missing R12 scenario snapshot", raises=ValueError)
32-
def test_run(scenario) -> None: # noqa: F811
57+
@MARK
58+
def test_run(scenario: Scenario) -> None:
3359
run(scenario)
3460
# TODO Add assertions once test scenario is available
61+
62+
63+
@pytest.mark.parametrize(
64+
"func",
65+
[
66+
pytest.param(run_ch4_reporting, marks=MARK),
67+
pytest.param(run_fe_reporting, marks=MARK),
68+
run_fe_methanol_nh3_reporting,
69+
pytest.param(run_fs_reporting, marks=MARK),
70+
pytest.param(run_prod_reporting, marks=MARK),
71+
],
72+
)
73+
def test_other(reporter: Reporter, func) -> None:
74+
"""Placeholder tests for several functions with identical signatures."""
75+
result = func(reporter, "model name", "scenario name")
76+
77+
# TODO Add assertions
78+
del result
79+
80+
81+
@MARK
82+
def test_split_fe_other(reporter: Reporter) -> None:
83+
split_fe_other(
84+
reporter,
85+
# NB IamDataFrame() can't be initialized empty or with an empty df; this is the
86+
# shortest call that works
87+
pyam.IamDataFrame(
88+
pd.DataFrame(
89+
[["m", "s", "r", "v", "u", 0]],
90+
columns=["model", "scenario", "region", "variable", "unit", "year"],
91+
).assign(value=1.0)
92+
),
93+
"model name",
94+
"scenario name",
95+
)

0 commit comments

Comments
 (0)