Skip to content

Commit b7f6b0d

Browse files
author
Robbie Muir
committed
Added test for missing highspy
1 parent 174ec99 commit b7f6b0d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

linopy/solvers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def solve_problem_from_file(
457457
# Use HiGHS to parse the problem file and find the set of variable names, needed to parse solution
458458
if "highs" not in available_solvers:
459459
raise ModuleNotFoundError(
460-
f"highspy is not installed. Please install it to use {self.solver_name} solver."
460+
f"highspy is not installed. Please install it to use {self.solver_name.name} solver."
461461
)
462462

463463
h = highspy.Highs()

test/test_solvers.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111

12-
from linopy import solvers
12+
from linopy import Model, solvers
1313

1414
free_mps_problem = """NAME sample_mip
1515
ROWS
@@ -64,3 +64,19 @@ def test_free_mps_solution_parsing(solver: str, tmp_path: Path) -> None:
6464

6565
assert result.status.is_ok
6666
assert result.solution.objective == 30.0
67+
68+
69+
def test_highs_missing(monkeypatch):
70+
# Mock the value of "available_solvers" to exclude "highs"
71+
monkeypatch.setattr("linopy.solvers.available_solvers", ["cbc"])
72+
73+
model = Model()
74+
x = model.add_variables(lower=0.0, name="x")
75+
model.add_constraints(x >= 0.0)
76+
model.add_objective(x, sense="min")
77+
78+
with pytest.raises(
79+
ModuleNotFoundError,
80+
match="highspy is not installed. Please install it to use CBC solve",
81+
):
82+
model.solve(solver_name="cbc")

0 commit comments

Comments
 (0)