Skip to content

Commit ea49a1c

Browse files
committed
Update tests for #259
- Set units for 'output' param in .ldv.prepare_tech_econ().
1 parent bc16f6d commit ea49a1c

File tree

8 files changed

+35
-18
lines changed

8 files changed

+35
-18
lines changed

message_ix_models/model/transport/ldv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def prepare_tech_econ(
299299

300300
# Create base quantity for "output" parameter
301301
nty = tuple("nty")
302-
c.add(k.output[0] * nty, wildcard(1.0, "", nty))
302+
c.add(k.output[0] * nty, wildcard(1.0, "Gv km", nty))
303303
for i, coords in enumerate(["n::ex world", "t::LDV", "y::model"]):
304304
c.add(
305305
k.output[i + 1] * nty,

message_ix_models/model/transport/testing.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
# appearing in the dict.
3131
MARK: dict[int, pytest.MarkDecorator] = {
3232
0: pytest.mark.xfail(
33-
reason="Missing R14 input data/assumptions", raises=FileNotFoundError
33+
reason="Missing R14 input data/config", raises=FileNotFoundError
3434
),
3535
1: pytest.mark.skip(
36-
reason="Currently only possible with regions=R12 input data/assumptions",
36+
reason="Currently only possible with regions=R12 input data/config",
3737
),
3838
3: pytest.mark.xfail(raises=ValueError, reason="Missing ISR/mer-to-ppp.csv"),
3939
4: pytest.mark.xfail(reason="Currently unsupported"),
@@ -46,6 +46,7 @@
4646
raises=ModelError,
4747
reason="Temporary, for https://github.com/iiasa/message-ix-models/pull/281",
4848
),
49+
9: pytest.mark.xfail(reason="Missing R14 input data/config"),
4950
}
5051

5152
make_mark: dict[int, Callable[..., pytest.MarkDecorator]] = {

message_ix_models/tests/model/transport/test_build.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,14 @@ def test_build_existing(tmp_path, test_context, url, solve=False):
276276
@pytest.mark.parametrize(
277277
"build_kw",
278278
(
279-
dict(regions="R11", years="A", options=dict()),
280-
dict(regions="R11", years="B", options=dict()),
279+
dict(regions="R11", years="A"),
280+
dict(regions="R11", years="B"),
281281
dict(regions="R11", years="B", options=dict(futures_scenario="A---")),
282282
dict(regions="R11", years="B", options=dict(futures_scenario="debug")),
283-
dict(regions="R12", years="B", options=dict()),
283+
dict(regions="R12", years="B"),
284284
dict(regions="R12", years="B", options=dict(navigate_scenario="act+ele+tec")),
285-
dict(regions="R14", years="B", options=dict()),
286-
param(dict(regions="ISR", years="A", options=dict()), marks=MARK[3]),
285+
param(dict(regions="R14", years="B"), marks=MARK[9]),
286+
param(dict(regions="ISR", years="A"), marks=MARK[3]),
287287
),
288288
)
289289
def test_debug(

message_ix_models/tests/model/transport/test_data.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pytest
33
from iam_units import registry
44

5-
from message_ix_models.model.transport import build, testing
5+
from message_ix_models.model.transport import build, non_ldv, testing
66
from message_ix_models.model.transport.CHN_IND import get_chn_ind_data, get_chn_ind_pop
77
from message_ix_models.model.transport.roadmap import get_roadmap_data
88
from message_ix_models.model.transport.testing import MARK, assert_units, make_mark
@@ -73,7 +73,7 @@ def test_get_non_ldv_data(test_context, regions, years="B"):
7373
c, _ = testing.configure_build(ctx, regions=regions, years=years)
7474

7575
# Code runs
76-
data = c.get("transport nonldv::ixmp")
76+
data = c.get(f"transport{non_ldv.Pi}")
7777

7878
# Data are provided for the these parameters
7979
exp_pars = {
@@ -189,7 +189,13 @@ def test_get_chn_ind_pop():
189189
@build.get_computer.minimum_version
190190
@pytest.mark.parametrize("years", ["A", "B"])
191191
@pytest.mark.parametrize(
192-
"regions", [pytest.param("ISR", marks=MARK[3]), "R11", "R12", "R14"]
192+
"regions",
193+
[
194+
pytest.param("ISR", marks=MARK[3]),
195+
"R11",
196+
"R12",
197+
pytest.param("R14", marks=MARK[9]),
198+
],
193199
)
194200
@pytest.mark.parametrize("options", [{}, dict(navigate_scenario=T35_POLICY.ELE)])
195201
def test_navigate_ele(test_context, regions, years, options):

message_ix_models/tests/model/transport/test_ikarus.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[
1818
("R11", 11),
1919
("R12", 12),
20-
("R14", 14),
20+
pytest.param("R14", 14, marks=testing.MARK[9]),
2121
pytest.param("ISR", 1, marks=testing.MARK[3]),
2222
],
2323
)

message_ix_models/tests/model/transport/test_ldv.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
@pytest.mark.parametrize("dummy_LDV", [False, True])
2121
@pytest.mark.parametrize("years", ["A", "B"])
2222
@pytest.mark.parametrize(
23-
"regions", [param("ISR", marks=testing.MARK[3]), "R11", "R12", "R14"]
23+
"regions",
24+
[
25+
param("ISR", marks=testing.MARK[3]),
26+
"R11",
27+
"R12",
28+
pytest.param("R14", marks=testing.MARK[9]),
29+
],
2430
)
2531
def test_get_ldv_data(tmp_path, test_context, dummy_LDV, regions, years) -> None:
2632
# Info about the corresponding RES
@@ -80,6 +86,9 @@ def test_get_ldv_data(tmp_path, test_context, dummy_LDV, regions, years) -> None
8086
)
8187

8288
# Output data is returned and has the correct units
89+
# for k, df_group in data["output"].groupby("unit"):
90+
# if k == "": # DEBUG Show data with particular units
91+
# print(df_group.to_string())
8392
assert {"Gp km", "Gv km", "Gv * km", "km", "-"} >= set(
8493
data["output"]["unit"].unique()
8594
)
@@ -170,7 +179,7 @@ def include(arg):
170179
[
171180
("R11", 11),
172181
("R12", 12),
173-
("R14", 14),
182+
param("R14", 14, marks=testing.MARK[9]),
174183
],
175184
)
176185
def test_ldv_capacity_factor(test_context, regions, N_node_loc, years="B"):
@@ -192,7 +201,7 @@ def test_ldv_capacity_factor(test_context, regions, N_node_loc, years="B"):
192201
(False, "R11", "A"),
193202
(False, "R11", "B"),
194203
(False, "R12", "B"),
195-
(False, "R14", "A"),
204+
param(False, "R14", "A", marks=testing.MARK[9]),
196205
# Not implemented
197206
param(False, "ISR", "A", marks=testing.MARK[3]),
198207
],

message_ix_models/tests/model/transport/test_report.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from copy import deepcopy
33
from typing import TYPE_CHECKING
44

5-
import genno
65
import pytest
76
from pytest import mark, param
87

@@ -61,7 +60,7 @@ def test_configure_legacy():
6160
(
6261
param("R11", "A", marks=make_mark[2](ValueError)),
6362
param("R12", "B", marks=MARK[8]),
64-
param("R14", "A", marks=make_mark[2](genno.ComputationError)),
63+
param("R14", "A", marks=MARK[9]),
6564
param("ISR", "A", marks=MARK[3]),
6665
),
6766
)

message_ix_models/tests/project/ssp/test_transport.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pandas as pd
44
import pytest
55

6+
from message_ix_models.model.transport.testing import MARK
67
from message_ix_models.project.ssp.transport import main
78
from message_ix_models.tests.tools.iea.test_web import user_local_data # noqa: F401
89
from message_ix_models.util import package_data_path
@@ -79,6 +80,7 @@ def input_xlsx_path(tmp_path_factory, input_csv_path) -> "pathlib.Path":
7980
}
8081

8182

83+
@MARK[8]
8284
@main.minimum_version
8385
# @pytest.mark.usefixtures("user_local_data")
8486
@pytest.mark.parametrize("method", ("A", "B"))
@@ -152,7 +154,7 @@ def test_cli(tmp_path, mix_models_cli, input_xlsx_path) -> None:
152154
copyfile(input_file, path_in)
153155

154156
# Code runs
155-
result = mix_models_cli.invoke(["ssp", "transport", f"{path_in}"])
157+
result = mix_models_cli.invoke(["ssp", "transport", "--method=A", f"{path_in}"])
156158
assert 0 == result.exit_code, result.output
157159

158160
# Output path was determined automatically and exists

0 commit comments

Comments
 (0)