Skip to content

Commit

Permalink
test: refactor congestion surplus tests for new get_bus_demand behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
danielolsen committed Feb 4, 2022
1 parent 36cfcee commit f5e67b4
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions postreise/analyze/transmission/tests/test_congestion_surplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@ def _check_return(expected_return, surplus):
def test_calculate_congestion_surplus_single_time(monkeypatch):
"""Congested case from Kirschen & Strbac Section 5.3.2.4"""

def mock_get_data(*args, **kwargs):
return demand

# Override default InputData.get_data method to avoid profile csv lookup
monkeypatch.setattr(InputData, "get_data", mock_get_data)

demand = pd.DataFrame({"UTC": ["t1"], 1: [410], 2: [0]})
bus_demand = pd.DataFrame({"UTC": ["t1"], 1: [50], 2: [60], 3: [300], 4: [0]})
lmp = pd.DataFrame({"UTC": ["t1"], 1: [7.5], 2: [11.25], 3: [10], 4: [0]})
pg = pd.DataFrame({"UTC": ["t1"], "A": [50], "B": [285], "C": [0], "D": [75]})
for df in (demand, lmp, pg):
for df in (bus_demand, lmp, pg):
df.set_index("UTC", inplace=True)
mock_scenario = MockScenario(grid_attrs, demand=demand, lmp=lmp, pg=pg)
mock_scenario = MockScenario(grid_attrs, bus_demand=bus_demand, lmp=lmp, pg=pg)

expected_return = pd.Series(
data=[787.5],
Expand All @@ -56,14 +50,10 @@ def mock_get_data(*args, **kwargs):
def test_calculate_congestion_surplus_three_times(monkeypatch):
"""First: congested. Second: uncongested. Third: uncongested, fuzzy."""

def mock_get_data(*args, **kwargs):
return demand

# Override default InputData.get_data method to avoid profile csv lookup
monkeypatch.setattr(InputData, "get_data", mock_get_data)

time_indices = ["t1", "t2", "t3"]
demand = pd.DataFrame({"UTC": time_indices, 1: [410] * 3, 2: [0] * 3})
bus_demand = pd.DataFrame(
{"UTC": time_indices, 1: [50] * 3, 2: [60] * 3, 3: [300] * 3, 4: [0] * 3}
)
lmp = pd.DataFrame(
{
"UTC": time_indices,
Expand All @@ -82,9 +72,9 @@ def mock_get_data(*args, **kwargs):
"D": [75, 0, 0],
}
)
for df in (demand, lmp, pg):
for df in (bus_demand, lmp, pg):
df.set_index("UTC", inplace=True)
mock_scenario = MockScenario(grid_attrs, demand=demand, lmp=lmp, pg=pg)
mock_scenario = MockScenario(grid_attrs, bus_demand=bus_demand, lmp=lmp, pg=pg)

expected_return = pd.Series(
data=[787.5, 0, 0],
Expand Down

0 comments on commit f5e67b4

Please sign in to comment.