Skip to content

Commit 6f04e88

Browse files
adrivincamacflo8
authored andcommitted
Improve Mock and mark.para in test function
1 parent 857c7ae commit 6f04e88

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

message_ix_models/tests/model/water/data/test_water_for_ppl.py

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import Literal
2+
13
import pandas as pd
24
import pytest
35
from message_ix import Scenario
@@ -209,40 +211,29 @@ def test_non_cooling_tec(request, test_context):
209211

210212
# Mock function for scen.par
211213
class MockScenario:
212-
def par(self, param, filters):
213-
if param == "bound_activity_up":
214-
return pd.DataFrame(
215-
{
216-
"node_loc": ["R12_AFR", "R12_AFR", "R12_AFR"],
217-
"technology": ["coal_ppl", "coal_ppl", "coal_ppl"],
218-
"year_act": [2030, 2040, 2050],
219-
"value": [30, 15, 0],
220-
}
221-
)
222-
elif param == "bound_new_capacity_up":
223-
return pd.DataFrame(
224-
{
225-
"node_loc": ["R12_AFR", "R12_AFR", "R12_AFR"],
226-
"technology": ["coal_ppl", "coal_ppl", "coal_ppl"],
227-
"year_vtg": [2030, 2040, 2050],
228-
"value": [30, 15, 0],
229-
}
230-
)
231-
return pd.DataFrame()
232-
233-
234-
@pytest.mark.parametrize("constraint_type", ["activity", "new_capacity"])
235-
def test_relax_growth_constraint(constraint_type):
236-
# Sample data for g_lo
237-
if constraint_type == "activity":
238-
year_type = "year_act"
239-
elif constraint_type == "new_capacity":
240-
year_type = "year_vtg"
241-
else:
242-
raise ValueError(
243-
"Invalid constraint_type. Must be 'activity' or 'new_capacity'."
214+
def par(
215+
self,
216+
param: Literal["bound_activity_up", "bound_new_capacity_up"],
217+
filters: dict,
218+
) -> pd.DataFrame:
219+
year_type = "year_act" if param == "bound_activity_up" else "year_vtg"
220+
221+
return pd.DataFrame(
222+
{
223+
"node_loc": ["R12_AFR", "R12_AFR", "R12_AFR"],
224+
"technology": ["coal_ppl", "coal_ppl", "coal_ppl"],
225+
year_type: [2030, 2040, 2050],
226+
"value": [30, 15, 0],
227+
}
244228
)
245229

230+
231+
@pytest.mark.parametrize(
232+
"constraint_type, year_type",
233+
[("activity", "year_act"), ("new_capacity", "year_vtg")],
234+
)
235+
def test_relax_growth_constraint(constraint_type, year_type):
236+
# Sample data for g_lo
246237
g_lo = pd.DataFrame(
247238
{
248239
"node_loc": ["R12_AFR", "R12_AFR", "R12_AFR", "R12_AFR"],

0 commit comments

Comments
 (0)