Skip to content

Commit

Permalink
Update tests for #259
Browse files Browse the repository at this point in the history
- Set units for 'output' param in .ldv.prepare_tech_econ().
- .transport.files.population_suburb_share is required.
  • Loading branch information
khaeru committed Jan 29, 2025
1 parent 7e40743 commit 879d942
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
1 change: 0 additions & 1 deletion message_ix_models/model/transport/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ def read_structures() -> "sdmx.message.StructureMessage":
key="population suburb share:n-y:exo",
name="Share of MSA population that is suburban",
units="dimensionless",
required=False,
)

speed = add(
Expand Down
2 changes: 1 addition & 1 deletion message_ix_models/model/transport/ldv.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def prepare_tech_econ(

# Create base quantity for "output" parameter
nty = tuple("nty")
c.add(k.output[0] * nty, wildcard(1.0, "", nty))
c.add(k.output[0] * nty, wildcard(1.0, "Gv km", nty))
for i, coords in enumerate(["n::ex world", "t::LDV", "y::model"]):
c.add(
k.output[i + 1] * nty,
Expand Down
10 changes: 5 additions & 5 deletions message_ix_models/tests/model/transport/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,14 +276,14 @@ def test_build_existing(tmp_path, test_context, url, solve=False):
@pytest.mark.parametrize(
"build_kw",
(
dict(regions="R11", years="A", options=dict()),
dict(regions="R11", years="B", options=dict()),
dict(regions="R11", years="A"),
dict(regions="R11", years="B"),
dict(regions="R11", years="B", options=dict(futures_scenario="A---")),
dict(regions="R11", years="B", options=dict(futures_scenario="debug")),
dict(regions="R12", years="B", options=dict()),
dict(regions="R12", years="B"),
dict(regions="R12", years="B", options=dict(navigate_scenario="act+ele+tec")),
dict(regions="R14", years="B", options=dict()),
param(dict(regions="ISR", years="A", options=dict()), marks=MARK[3]),
param(dict(regions="R14", years="B"), marks=MARK[0]),
param(dict(regions="ISR", years="A"), marks=MARK[3]),
),
)
def test_debug(
Expand Down
12 changes: 9 additions & 3 deletions message_ix_models/tests/model/transport/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from iam_units import registry

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

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

# Data are provided for the these parameters
exp_pars = {
Expand Down Expand Up @@ -189,7 +189,13 @@ def test_get_chn_ind_pop():
@build.get_computer.minimum_version
@pytest.mark.parametrize("years", ["A", "B"])
@pytest.mark.parametrize(
"regions", [pytest.param("ISR", marks=MARK[3]), "R11", "R12", "R14"]
"regions",
[
pytest.param("ISR", marks=MARK[3]),
"R11",
"R12",
pytest.param("R14", marks=MARK[0]),
],
)
@pytest.mark.parametrize("options", [{}, dict(navigate_scenario=T35_POLICY.ELE)])
def test_navigate_ele(test_context, regions, years, options):
Expand Down
2 changes: 1 addition & 1 deletion message_ix_models/tests/model/transport/test_ikarus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[
("R11", 11),
("R12", 12),
("R14", 14),
pytest.param("R14", 14, marks=testing.MARK[0]),
pytest.param("ISR", 1, marks=testing.MARK[3]),
],
)
Expand Down
15 changes: 12 additions & 3 deletions message_ix_models/tests/model/transport/test_ldv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
@pytest.mark.parametrize("dummy_LDV", [False, True])
@pytest.mark.parametrize("years", ["A", "B"])
@pytest.mark.parametrize(
"regions", [param("ISR", marks=testing.MARK[3]), "R11", "R12", "R14"]
"regions",
[
param("ISR", marks=testing.MARK[3]),
"R11",
"R12",
pytest.param("R14", marks=testing.MARK[0]),
],
)
def test_get_ldv_data(tmp_path, test_context, dummy_LDV, regions, years) -> None:
# Info about the corresponding RES
Expand Down Expand Up @@ -80,6 +86,9 @@ def test_get_ldv_data(tmp_path, test_context, dummy_LDV, regions, years) -> None
)

# Output data is returned and has the correct units
# for k, df_group in data["output"].groupby("unit"):
# if k == "": # DEBUG Show data with particular units
# print(df_group.to_string())
assert {"Gp km", "Gv km", "Gv * km", "km", "-"} >= set(
data["output"]["unit"].unique()
)
Expand Down Expand Up @@ -170,7 +179,7 @@ def include(arg):
[
("R11", 11),
("R12", 12),
("R14", 14),
param("R14", 14, marks=testing.MARK[0]),
],
)
def test_ldv_capacity_factor(test_context, regions, N_node_loc, years="B"):
Expand All @@ -192,7 +201,7 @@ def test_ldv_capacity_factor(test_context, regions, N_node_loc, years="B"):
(False, "R11", "A"),
(False, "R11", "B"),
(False, "R12", "B"),
(False, "R14", "A"),
param(False, "R14", "A", marks=testing.MARK[0]),
# Not implemented
param(False, "ISR", "A", marks=testing.MARK[3]),
],
Expand Down
3 changes: 1 addition & 2 deletions message_ix_models/tests/model/transport/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from copy import deepcopy
from typing import TYPE_CHECKING

import genno
import pytest
from pytest import mark, param

Expand Down Expand Up @@ -61,7 +60,7 @@ def test_configure_legacy():
(
param("R11", "A", marks=make_mark[2](ValueError)),
param("R12", "B", marks=MARK[8]),
param("R14", "A", marks=make_mark[2](genno.ComputationError)),
param("R14", "A", marks=MARK[0]),
param("ISR", "A", marks=MARK[3]),
),
)
Expand Down
4 changes: 3 additions & 1 deletion message_ix_models/tests/project/ssp/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from message_ix_models.project.ssp.transport import main
from message_ix_models.tests.tools.iea.test_web import user_local_data # noqa: F401
from message_ix_models.transport.testing import MARK
from message_ix_models.util import package_data_path

if TYPE_CHECKING:
Expand Down Expand Up @@ -81,6 +82,7 @@ def input_xlsx_path(tmp_path_factory, input_csv_path) -> "pathlib.Path":

@main.minimum_version
# @pytest.mark.usefixtures("user_local_data")
@MARK[8]
@pytest.mark.parametrize("method", ("A", "B"))
def test_main(tmp_path, test_context, input_csv_path, method) -> None:
"""Code can be called from Python."""
Expand Down Expand Up @@ -152,7 +154,7 @@ def test_cli(tmp_path, mix_models_cli, input_xlsx_path) -> None:
copyfile(input_file, path_in)

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

# Output path was determined automatically and exists
Expand Down

0 comments on commit 879d942

Please sign in to comment.