Skip to content

Commit

Permalink
Fix broken test for utils.solver with symengine (#1340)
Browse files Browse the repository at this point in the history
* repair broken test

* add RN

* resolve review comments
  • Loading branch information
cdiener committed Sep 1, 2023
1 parent e48bc84 commit 9e48208
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 3 additions & 1 deletion release-notes/next-release.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Release notes for cobrapy x.y.z
# Release notes for cobrapy 0.27.0

## New features

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

Repair a broken test for `fix_objective_as_constraint`.

## Other

Backwards compatibility for pickled models has been improved.
Expand Down
19 changes: 11 additions & 8 deletions tests/test_util/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ def test_absolute_expression(model: "Model") -> None:
def test_fix_objective_as_constraint(solver: str, model: "Model") -> None:
"""Test fixing present objective as a constraint."""
model.solver = solver
opt = model.slim_optimize()
with model as m:
su.fix_objective_as_constraint(model, 1.0)
constraint_name = m.constraints[-1]
assert abs(m.constraints[-1].expression - m.objective.expression) < 1e-6
assert constraint_name not in m.constraints
su.fix_objective_as_constraint(model)
constraint_name = model.constraints[-1]
assert abs(model.constraints[-1].expression - model.objective.expression) < 1e-6
assert constraint_name in model.constraints
su.fix_objective_as_constraint(model, 1.0, name="fixed")
assert (m.constraints.fixed.expression - m.objective.expression).simplify() == 0
assert m.constraints.fixed.lb == pytest.approx(opt)
assert "fixed" not in m.constraints
su.fix_objective_as_constraint(model, name="fixed")
assert (
model.constraints.fixed.expression - model.objective.expression
).simplify() == 0
assert m.constraints.fixed.lb == pytest.approx(opt)
assert "fixed" in model.constraints


@pytest.mark.parametrize("solver", optlang_solvers)
Expand Down

0 comments on commit 9e48208

Please sign in to comment.