Skip to content

Commit 1d6d4db

Browse files
committed
improve test coverage
1 parent 1b5f8a8 commit 1d6d4db

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

test/test_optimization.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -386,26 +386,6 @@ def test_default_setting_sol_and_dual_accessor(
386386
assert model.matrices.dual[0] == model.dual["con0"]
387387

388388

389-
@pytest.mark.parametrize(
390-
"solver,io_api,explicit_coordinate_names", [p for p in params if p[0] == "xpress"]
391-
)
392-
def test_old_xpress_version(
393-
model: Model, solver: str, io_api: str, explicit_coordinate_names: bool
394-
) -> None:
395-
with patch("xpress.__version__", "9.5.0"):
396-
status, _ = model.solve(
397-
solver, io_api=io_api, explicit_coordinate_names=explicit_coordinate_names
398-
)
399-
assert status == "ok"
400-
x = model["x"]
401-
assert_equal(x.solution, model.solution["x"])
402-
c = model.constraints["con1"]
403-
assert_equal(c.dual, model.dual["con1"])
404-
# squeeze in dual getter in matrix
405-
assert len(model.matrices.dual) == model.ncons
406-
assert model.matrices.dual[0] == model.dual["con0"]
407-
408-
409389
@pytest.mark.parametrize("solver,io_api,explicit_coordinate_names", params)
410390
def test_default_setting_expression_sol_accessor(
411391
model: Model, solver: str, io_api: str, explicit_coordinate_names: bool
@@ -662,6 +642,32 @@ def test_model_with_inf(
662642
assert (model_with_inf.solution.y == 10).all()
663643

664644

645+
@pytest.mark.skipif(
646+
"xpress" not in available_solvers, reason="Xpress solver not available"
647+
)
648+
def test_old_xpress_version_no_dual(model_with_inf: Model) -> None:
649+
# Confirm that the old code path for xpress 9.5.x still works (when duals are not available)
650+
with patch("xpress.__version__", "9.5.0"):
651+
_, condition = model_with_inf.solve("xpress")
652+
assert condition == "optimal"
653+
assert (model_with_inf.solution.x == 0).all()
654+
assert (model_with_inf.solution.y == 10).all()
655+
assert len(len(model_with_inf.dual.keys())) == 0
656+
657+
658+
@pytest.mark.skipif(
659+
"xpress" not in available_solvers, reason="Xpress solver not available"
660+
)
661+
def test_old_xpress_version_with_dual(model: Model) -> None:
662+
# Confirm that the old code path for xpress 9.5.x still works (when duals are available)
663+
with patch("xpress.__version__", "9.5.0"):
664+
status, condition = model.solve("xpress")
665+
assert status == "ok"
666+
assert condition == "optimal"
667+
assert np.isclose(model.objective.value or 0, 3.3)
668+
assert np.isclose(model.dual["con0"].values, 0.3)
669+
670+
665671
@pytest.mark.parametrize(
666672
"solver,io_api,explicit_coordinate_names",
667673
[p for p in params if p[0] not in ["mindopt"]],

0 commit comments

Comments
 (0)