Skip to content

Commit 0f0511c

Browse files
committed
Fix CI tests
1 parent 9bae582 commit 0f0511c

File tree

13 files changed

+20
-54
lines changed

13 files changed

+20
-54
lines changed

src/pownet/folder_utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,3 @@ def get_database_dir() -> str:
1919
def get_test_dir() -> str:
2020
"""Returns the test directory of the pownet package."""
2121
return os.path.join(get_pownet_dir(), "src", "test_pownet")
22-
23-
24-
def get_test_model_dir() -> str:
25-
"""Returns the test directory of the pownet package."""
26-
return os.path.join(get_pownet_dir(), "src", "test_pownet", "test_model_library")

src/pownet/reservoir/solve_release.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ def solve_release_from_dispatch(
234234
6. Definition of spill_bar
235235
spill_bar = INFLOW_t + storage_t-1 - STORAGE_MAX - release_t
236236
237-
7. Spill cannot be positive when storage is less than max_storage
238-
spill <= 0 when storage_t < max_storage
239-
spill >= 0 when storage_t > max_storage
240-
241-
242237
Note that the objective function is not linear because of the absolute value.
243238
To make it linear, we introduce a new variable mismatch_t and rewrite
244239
the objective function as:
@@ -270,15 +265,10 @@ def solve_release_from_dispatch(
270265

271266
# Unbounded hydropower
272267
unb_hourly_hydropower = model.addVar(lb=0.0, name="unb_hourly_hydropower")
273-
274268
# Bounded hydropower
275269
hourly_hydropower = model.addVar(lb=0.0, name="hourly_hydropower")
276270
daily_hydropower = model.addVar(lb=0.0, name="daily_hydropower")
277271

278-
# Binary variable for spill condition
279-
delta = model.addVar(vtype=gp.GRB.BINARY, name="delta")
280-
big_m = storage_max * 2
281-
282272
# Set objective
283273
model.setObjective(mismatch, gp.GRB.MINIMIZE)
284274

@@ -345,17 +335,6 @@ def solve_release_from_dispatch(
345335
# (6) Define spill
346336
model.addConstr(spill == gp.max_(0, spill_bar), name="c_spill")
347337

348-
# (7) Model the conditional spill constraint using binary variable and big-M
349-
model.addConstr(spill <= big_m * delta, name="c_spill_conditional_upper")
350-
model.addConstr(
351-
storage <= storage_max - 1e-6 + big_m * (1 - delta),
352-
name="c_storage_less_than_max",
353-
) # 1e-6 is a small tolerance (epsilon)
354-
model.addConstr(
355-
storage >= storage_max + 1e-6 - big_m * delta,
356-
name="c_storage_greater_than_equal_to_max",
357-
) # 1e-6 is a small tolerance (epsilon)
358-
359338
############################
360339
# Solve the optimization problem
361340
############################

src/test_pownet/test_builder/__init__.py

Whitespace-only changes.

src/test_pownet/test_core/test_builder.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
"""Tests for the ModelBuilder class."""
1+
""" Unit tests for the ModelBuilder class.
2+
"""
23

34
import os
45
import unittest
5-
from pownet import ModelBuilder, SystemInput
6-
7-
from pownet.builder.thermal import ThermalUnitBuilder
8-
from pownet.builder.hydro import HydroUnitBuilder
9-
from pownet.builder.nondispatch import NonDispatchUnitBuilder
10-
from pownet.builder.energy_storage import EnergyStorageUnitBuilder
11-
from pownet.builder.system import SystemBuilder
6+
from pownet.core import ModelBuilder, SystemInput
7+
from pownet.folder_utils import get_model_dir
128

139

1410
class TestModelBuilder(unittest.TestCase):
1511
"""Unless otherwise stated, use "dummy_trade" over 24-hr as the test case."""
1612

1713
def setUp(self) -> None:
1814
# Load the test data
19-
test_model_library_path = os.path.join(
20-
os.path.dirname(__file__), "..", "test_model_library"
15+
test_model_library_path = os.path.abspath(
16+
os.path.join(os.path.dirname(__file__), "..", "test_model_library")
2117
)
22-
print(f"Test model library path: {test_model_library_path}")
2318

2419
self.inputs = SystemInput(
2520
input_folder=test_model_library_path,
@@ -33,18 +28,9 @@ def setUp(self) -> None:
3328
self.model_builder = ModelBuilder(self.inputs)
3429

3530
def test_init(self):
36-
self.assertIsInstance(self.model_builder.thermal_builder, ThermalUnitBuilder)
37-
self.assertIsInstance(self.model_builder.hydro_builder, HydroUnitBuilder)
38-
self.assertIsInstance(
39-
self.model_builder.nondispatch_builder, NonDispatchUnitBuilder
40-
)
41-
self.assertIsInstance(
42-
self.model_builder.storage_builder, EnergyStorageUnitBuilder
31+
self.assertEqual(
32+
self.model_builder.timesteps, range(1, self.inputs.sim_horizon + 1)
4333
)
44-
self.assertIsInstance(self.model_builder.system_builder, SystemBuilder)
45-
46-
def test_build(self):
47-
pass
4834

4935

5036
if __name__ == "__main__":

src/test_pownet/test_core/test_data_processor.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
"""test_data_processor.py"""
1+
""" This is test_data_processor.py
2+
"""
23

34
import os
45
import unittest
56
from pownet.core.data_processor import (
67
DataProcessor,
78
)
89

10+
from pownet.folder_utils import get_model_dir
11+
912

1013
class TestDataProcessor(unittest.TestCase):
1114
def test_initialization(self):
1215
# Arrange
13-
test_model_library_path = os.path.join(
14-
os.path.dirname(__file__), "..", "test_model_library"
16+
test_model_library_path = os.path.abspath(
17+
os.path.join(os.path.dirname(__file__), "..", "test_model_library")
1518
)
1619
model_name = "dummy"
1720
year = 2024
@@ -34,7 +37,7 @@ def test_initialization(self):
3437
self.assertEqual(processor.wavelength, 6000)
3538
self.assertEqual(
3639
processor.model_folder,
37-
os.path.join(test_model_library_path, model_name),
40+
os.path.join(get_model_dir(), test_model_library_path, model_name),
3841
)
3942
# Timeseries should have 8760 rows
4043
self.assertEqual(processor.cycle_map, {})

src/test_pownet/test_coupler.py

Whitespace-only changes.

src/test_pownet/test_data_model/__init__.py

Whitespace-only changes.

src/test_pownet/test_model.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
"""test_model.py"""
1+
""" This is test_model.py
2+
"""
23

4+
import os
35
import unittest
6+
from unittest.mock import patch, MagicMock, call
47

58
import gurobipy as gp
69
import pandas as pd
7-
from pownet.optim_model import PowerSystemModel
10+
from pownet.modeling import PowerSystemModel
811

912

1013
class TestPowerSystemModel(unittest.TestCase):

src/test_pownet/test_optim_model/__init__.py

Whitespace-only changes.

src/test_pownet/test_optim_model/test_constraints/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)