Skip to content

Commit

Permalink
rename tests, update to cbc, add callable solver name in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddceruti committed Jul 19, 2024
1 parent d3031c4 commit 2289deb
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -25,11 +25,11 @@ jobs:
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
channels: conda-forge
channels: conda-forge, defaults
channel-priority: strict
- name: Install dependencies
run: |
conda install -c conda-forge pyscipopt
conda install coin-or-cbc
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
Expand All @@ -44,4 +44,4 @@ jobs:
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
pytest tests/run_sts_test.py --solver cbc
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def pytest_addoption(parser):
parser.addoption("--solver", action="store", default="scip",
help="Define the solver to use for the optimization. Default is cbc.")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 6 additions & 4 deletions test/run_sts_test.py → tests/run_sts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def read_regression(path, i):
return r_thermal_cap, r_heat_loss


def test_sts_forced():
def test_sts_forced(request):
"""Main function to run the optimization"""
solver_name = request.config.getoption("--solver")
# Load the district
current_path = os.path.dirname(os.path.abspath(__file__))
mat = tt.fileio.load(os.path.join(current_path, 'data'))
Expand All @@ -40,7 +41,7 @@ def test_sts_forced():
Optimization().economics, "forced")

# Optimization initialization
opt = pyo.SolverFactory('scip')
opt = pyo.SolverFactory(solver_name)
opt.options['mipgap'] = 0.01
opt.options['timelimit'] = 600

Expand All @@ -51,8 +52,9 @@ def test_sts_forced():
assert (abs(pyo.value(model.obj)) - 4.6259e+06) < 0.02 * 4.6259e+06


def test_sts_eco():
def test_sts_eco(request):
"""Main function to run the optimization"""
solver_name = request.config.getoption("--solver")
# Load the district
current_path = os.path.dirname(os.path.abspath(__file__))
mat = tt.fileio.load(os.path.join(current_path, 'data'))
Expand All @@ -66,7 +68,7 @@ def test_sts_eco():
Optimization().economics, "eco")

# Optimization initialization
opt = pyo.SolverFactory('scip')
opt = pyo.SolverFactory(solver_name)
opt.options['mipgap'] = 0.01
opt.options['timelimit'] = 600

Expand Down

0 comments on commit 2289deb

Please sign in to comment.