Skip to content

Commit 8400155

Browse files
committed
Migrate nexus test script from message_data
*in progress
1 parent 4d13e60 commit 8400155

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed

message_ix_models/tests/model/water/__init__.py

Whitespace-only changes.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
import pandas as pd
2+
import pytest
3+
from message_ix_models.model import bare
4+
5+
from message_data.model.water import build
6+
from message_data.model.water.data.demands import (
7+
add_irrigation_demand,
8+
add_sectoral_demands,
9+
add_water_availability,
10+
)
11+
from message_data.model.water.data.infrastructure import (
12+
add_desalination,
13+
add_infrastructure_techs,
14+
)
15+
from message_data.model.water.data.irrigation import add_irr_structure
16+
from message_data.model.water.data.water_for_ppl import cool_tech, non_cooling_tec
17+
from message_data.model.water.data.water_supply import add_e_flow, add_water_supply
18+
19+
pytestmark = pytest.mark.xfail(reason="The tests will be updated in the preceeding PR")
20+
21+
22+
def configure_build(context, regions, years):
23+
context.update(regions=regions, years=years)
24+
25+
# Information about the corresponding base model
26+
info = bare.get_spec(context)["add"]
27+
context["water build info"] = info
28+
context["water spec"] = build.get_spec(context)
29+
30+
return info
31+
32+
33+
# def test_build(request, test_context):
34+
# scenario = testing.bare_res(request, test_context)
35+
36+
# # Code runs on the bare RES
37+
# build(scenario)
38+
39+
# # New set elements were added
40+
# assert "extract_surfacewater" in scenario.set("technology").tolist()
41+
42+
43+
# def test_get_spec(session_context):
44+
# # Code runs
45+
# spec = get_spec()
46+
47+
# # Expected return type
48+
# assert isinstance(spec, dict) and len(spec) == 3
49+
50+
# # Contents are read correctly
51+
# assert "water_supply" in spec["require"].set["level"]
52+
53+
54+
# def test_read_config(session_context):
55+
# # read_config() returns a reference to the current context
56+
# context = read_config()
57+
# assert context is session_context
58+
59+
# # 'add' elements have been converted to Code objects
60+
# assert isinstance(context["water"]["set"]["technology"]["add"][0], Code)
61+
62+
63+
def test_read_data(test_context, regions, years):
64+
65+
context = test_context
66+
# info = configure_build(context, regions, years)
67+
68+
data_irr = add_irr_structure(context)
69+
70+
# Returns a mapping
71+
assert {"input", "output"} == set(data_irr.keys())
72+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_irr.values()))
73+
74+
data_water_ppl = cool_tech(context)
75+
76+
# Returns a mapping
77+
assert {
78+
"growth_activity_lo",
79+
"growth_activity_up",
80+
"input",
81+
"output",
82+
"capacity_factor",
83+
"addon_conversion",
84+
"addon_lo",
85+
"inv_cost",
86+
"historical_new_capacity",
87+
"emission_factor",
88+
"historical_activity",
89+
} == set(data_water_ppl.keys())
90+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_water_ppl.values()))
91+
92+
data_non_cool = non_cooling_tec(context)
93+
94+
# Returns a mapping
95+
assert {"input"} == set(data_non_cool.keys())
96+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_non_cool.values()))
97+
98+
data_infrastructure = add_infrastructure_techs(context)
99+
100+
# Returns a mapping
101+
assert {
102+
"input",
103+
"output",
104+
"capacity_factor",
105+
"technical_lifetime",
106+
"inv_cost",
107+
"fix_cost",
108+
"construction_time",
109+
} == set(data_non_cool.keys())
110+
assert all(
111+
map(lambda df: isinstance(df, pd.DataFrame), data_infrastructure.values())
112+
)
113+
114+
data_desal = add_desalination(context)
115+
# Returns a mapping
116+
assert {
117+
"input",
118+
"output",
119+
"bound_total_capacity_up",
120+
"historical_new_capacity",
121+
"inv_cost",
122+
"var_cost",
123+
"bound_activity_lo",
124+
"construction_time",
125+
"bound_total_capacity_up",
126+
} == set(data_desal.keys())
127+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_desal.values()))
128+
129+
data_demands = add_sectoral_demands(context)
130+
# Returns a mapping
131+
assert {"demand", "historical_new_capacity", "share_commodity_lo"} == set(
132+
data_demands.keys()
133+
)
134+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_demands.values()))
135+
136+
data_supply = add_water_supply(context)
137+
# Returns a mapping
138+
assert {
139+
"input",
140+
"output",
141+
"historical_new_capacity",
142+
"var_cost",
143+
"share_mode_up",
144+
"technical_lifetime",
145+
"inv_cost",
146+
"fix_cost",
147+
"",
148+
} == set(data_supply.keys())
149+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_supply.values()))
150+
151+
data_eflow = add_e_flow(context)
152+
# Returns a mapping
153+
assert {"bound_activity_lo"} == set(data_eflow.keys())
154+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_eflow.values()))
155+
156+
data_irr = add_irrigation_demand(context)
157+
# Returns a mapping
158+
assert {"land_input"} == set(data_irr.keys())
159+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_irr.values()))
160+
161+
data_irr = add_irrigation_demand(context)
162+
# Returns a mapping
163+
assert {"land_input"} == set(data_irr.keys())
164+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_irr.values()))
165+
166+
data_water_avail = add_water_availability(context)
167+
# Returns a mapping
168+
assert {"share_commodity_lo", "demand"} == set(data_water_avail.keys())
169+
assert all(map(lambda df: isinstance(df, pd.DataFrame), data_water_avail.values()))

0 commit comments

Comments
 (0)