Skip to content

Commit

Permalink
refactor: update tests for curtailment
Browse files Browse the repository at this point in the history
  • Loading branch information
rouille committed Sep 28, 2020
1 parent 7f37695 commit bd00a2c
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions postreise/analyze/generation/tests/test_curtailment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from powersimdata.tests.mock_scenario import MockScenario
from postreise.analyze.generation.curtailment import (
calculate_curtailment_time_series,
calculate_curtailment_percentage,
calculate_curtailment_time_series_by_resources,
calculate_curtailment_percentage_by_resources,
summarize_curtailment_by_bus,
summarize_curtailment_by_location,
)
Expand Down Expand Up @@ -81,46 +81,45 @@ def _check_curtailment_vs_expected(self, curtailment, expected):

def test_calculate_curtailment_time_series_solar(self):
expected_return = {"solar": mock_curtailment["solar"]}
curtailment = calculate_curtailment_time_series(scenario, resources=("solar",))
self._check_curtailment_vs_expected(curtailment, expected_return)

def test_calculate_curtailment_time_series_wind_tuple(self):
expected_return = {"wind": mock_curtailment["wind"]}
curtailment = calculate_curtailment_time_series(scenario, resources=("wind",))
self._check_curtailment_vs_expected(curtailment, expected_return)

def test_calculate_curtailment_time_series_wind_set(self):
expected_return = {"wind": mock_curtailment["wind"]}
curtailment = calculate_curtailment_time_series(scenario, resources={"wind"})
curtailment = calculate_curtailment_time_series_by_resources(
scenario, resources=("solar",)
)
self._check_curtailment_vs_expected(curtailment, expected_return)

def test_calculate_curtailment_time_series_wind_list(self):
def test_calculate_curtailment_time_series_wind_argument_type(self):
expected_return = {"wind": mock_curtailment["wind"]}
curtailment = calculate_curtailment_time_series(scenario, resources=["wind"])
self._check_curtailment_vs_expected(curtailment, expected_return)
arg = (
(scenario, "wind"),
(scenario, ("wind")),
(scenario, ["wind"]),
(scenario, {"wind"}),
)
for a in arg:
curtailment = calculate_curtailment_time_series_by_resources(a[0], a[1])
self._check_curtailment_vs_expected(curtailment, expected_return)

def test_calculate_curtailment_time_series_default(self):
expected_return = mock_curtailment
curtailment = calculate_curtailment_time_series(scenario)
curtailment = calculate_curtailment_time_series_by_resources(scenario)
self._check_curtailment_vs_expected(curtailment, expected_return)

def test_calculate_curtailment_time_series_solar_wind_tuple(self):
expected_return = {r: mock_curtailment[r] for r in ("solar", "wind")}
curtailment = calculate_curtailment_time_series(
curtailment = calculate_curtailment_time_series_by_resources(
scenario, resources=("solar", "wind")
)
self._check_curtailment_vs_expected(curtailment, expected_return)

def test_calculate_curtailment_time_series_solar_wind_set(self):
expected_return = {r: mock_curtailment[r] for r in ("solar", "wind")}
curtailment = calculate_curtailment_time_series(
curtailment = calculate_curtailment_time_series_by_resources(
scenario, resources={"solar", "wind"}
)
self._check_curtailment_vs_expected(curtailment, expected_return)

def test_calculate_curtailment_time_series_wind_solar_list(self):
expected_return = {r: mock_curtailment[r] for r in ("solar", "wind")}
curtailment = calculate_curtailment_time_series(
curtailment = calculate_curtailment_time_series_by_resources(
scenario, resources=["wind", "solar"]
)
self._check_curtailment_vs_expected(curtailment, expected_return)
Expand All @@ -129,7 +128,7 @@ def test_calculate_curtailment_time_series_wind_solar_list(self):
class TestCheckResourceInScenario(unittest.TestCase):
def test_error_geothermal_curtailment(self):
with self.assertRaises(ValueError):
curtailment = calculate_curtailment_time_series(
curtailment = calculate_curtailment_time_series_by_resources(
scenario, resources=("geothermal",)
)

Expand All @@ -138,65 +137,63 @@ def test_error_no_solar(self):
no_solar_grid_attrs = {"plant": no_solar_mock_plant}
no_solar_scenario = MockScenario(no_solar_grid_attrs)
with self.assertRaises(ValueError):
curtailment = calculate_curtailment_time_series(
curtailment = calculate_curtailment_time_series_by_resources(
no_solar_scenario, resources=("solar",)
)


class TestCalculateCurtailmentPercentage(unittest.TestCase):
def test_calculate_curtailment_percentage_solar(self):
expected_return = 3.5 / 25
total_curtailment = calculate_curtailment_percentage(
total_curtailment = calculate_curtailment_percentage_by_resources(
scenario, resources=("solar",)
)
self.assertAlmostEqual(total_curtailment, expected_return)

def test_calculate_curtailment_percentage_wind(self):
expected_return = 0.5 / 7
total_curtailment = calculate_curtailment_percentage(
total_curtailment = calculate_curtailment_percentage_by_resources(
scenario, resources=("wind",)
)
self.assertAlmostEqual(total_curtailment, expected_return)

def test_calculate_curtailment_percentage_wind_offshore(self):
expected_return = 2.5 / 16
total_curtailment = calculate_curtailment_percentage(
total_curtailment = calculate_curtailment_percentage_by_resources(
scenario, resources=("wind_offshore",)
)
self.assertAlmostEqual(total_curtailment, expected_return)

def test_calculate_curtailment_percentage_default(self):
expected_return = 6.5 / 48
total_curtailment = calculate_curtailment_percentage(scenario)
total_curtailment = calculate_curtailment_percentage_by_resources(scenario)
self.assertAlmostEqual(total_curtailment, expected_return)

def test_calculate_curtailment_percentage_solar_wind(self):
expected_return = 4 / 32
total_curtailment = calculate_curtailment_percentage(
total_curtailment = calculate_curtailment_percentage_by_resources(
scenario, resources=("solar", "wind")
)
self.assertAlmostEqual(total_curtailment, expected_return)


class TestSummarizeCurtailmentByBus(unittest.TestCase):
def test_summarize_curtailment_by_bus(self):
grid = scenario.state.get_grid()
expected_return = {
"solar": {1: 1, 2: 2.5},
"wind": {3: 0.5},
"wind_offshore": {4: 2.5},
}
bus_curtailment = summarize_curtailment_by_bus(mock_curtailment, grid)
bus_curtailment = summarize_curtailment_by_bus(scenario)
self.assertEqual(bus_curtailment, expected_return)


class TestSummarizeCurtailmentByLocation(unittest.TestCase):
def test_summarize_curtailment_by_location(self):
grid = scenario.state.get_grid()
expected_return = {
"solar": {(47.6, 122.3): 3.5},
"wind": {(37.8, 122.4): 0.5},
"wind_offshore": {(37.8, 122.4): 2.5},
}
location_curtailment = summarize_curtailment_by_location(mock_curtailment, grid)
location_curtailment = summarize_curtailment_by_location(scenario)
self.assertEqual(location_curtailment, expected_return)

0 comments on commit bd00a2c

Please sign in to comment.