Skip to content

Commit 9e48208

Browse files
authored
Fix broken test for utils.solver with symengine (#1340)
* repair broken test * add RN * resolve review comments
1 parent e48bc84 commit 9e48208

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

release-notes/next-release.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Release notes for cobrapy x.y.z
1+
# Release notes for cobrapy 0.27.0
22

33
## New features
44

@@ -12,6 +12,8 @@ has been removed.
1212
`loopless_solution` now fixes the objective to its optimum as in the
1313
originally published method and returns the objective value in the solution object.
1414

15+
Repair a broken test for `fix_objective_as_constraint`.
16+
1517
## Other
1618

1719
Backwards compatibility for pickled models has been improved.

tests/test_util/test_solver.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,18 @@ def test_absolute_expression(model: "Model") -> None:
118118
def test_fix_objective_as_constraint(solver: str, model: "Model") -> None:
119119
"""Test fixing present objective as a constraint."""
120120
model.solver = solver
121+
opt = model.slim_optimize()
121122
with model as m:
122-
su.fix_objective_as_constraint(model, 1.0)
123-
constraint_name = m.constraints[-1]
124-
assert abs(m.constraints[-1].expression - m.objective.expression) < 1e-6
125-
assert constraint_name not in m.constraints
126-
su.fix_objective_as_constraint(model)
127-
constraint_name = model.constraints[-1]
128-
assert abs(model.constraints[-1].expression - model.objective.expression) < 1e-6
129-
assert constraint_name in model.constraints
123+
su.fix_objective_as_constraint(model, 1.0, name="fixed")
124+
assert (m.constraints.fixed.expression - m.objective.expression).simplify() == 0
125+
assert m.constraints.fixed.lb == pytest.approx(opt)
126+
assert "fixed" not in m.constraints
127+
su.fix_objective_as_constraint(model, name="fixed")
128+
assert (
129+
model.constraints.fixed.expression - model.objective.expression
130+
).simplify() == 0
131+
assert m.constraints.fixed.lb == pytest.approx(opt)
132+
assert "fixed" in model.constraints
130133

131134

132135
@pytest.mark.parametrize("solver", optlang_solvers)

0 commit comments

Comments
 (0)