Skip to content

Commit e6f685d

Browse files
committed
Xpress Community License detection skip unsupported feature test
1 parent 3e3e0ad commit e6f685d

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

pyomo/contrib/solver/tests/solvers/test_xpress_direct.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
from pyomo.contrib.solver.common.results import SolutionStatus
2828
from pyomo.contrib.solver.solvers.xpress import XpressDirect
29-
from pyomo.contrib.solver.solvers.xpress.xpress_base import _exit_external_function
29+
from pyomo.contrib.solver.solvers.xpress.xpress_base import _exit_external_function, xp
3030
from pyomo.contrib.solver.tests.solvers._xpress_test_utils import (
3131
_simple_lp,
3232
_simple_mip,
@@ -732,7 +732,9 @@ def test_external_function_multiple(self):
732732
"""Two external functions in the same model.
733733
734734
Objective: f1(x) + f2(y) = x^2 + (y+1), x in [0,5], y in [0,5].
735-
Optimum: x=0, y=0, obj=1.
735+
Full license: optimum x=0, y=0, obj=1.
736+
Community license: only one user function is allowed, so the solve
737+
must surface Xpress error 1152 cleanly.
736738
"""
737739

738740
def f1(x):
@@ -747,16 +749,23 @@ def f2(y):
747749
m.f1 = pyo.ExternalFunction(function=f1)
748750
m.f2 = pyo.ExternalFunction(function=f2)
749751
m.obj = pyo.Objective(expr=m.f1(m.x) + m.f2(m.y))
750-
_solve_and_check(
751-
self,
752-
self.opt,
753-
m,
754-
{
755-
'status': SolutionStatus.feasible,
756-
'objective': 1.0,
757-
'vars': [(m.x, 0.0), (m.y, 0.0)],
758-
},
759-
)
752+
if xp.featurequery("Community"):
753+
# community raises "?1152 Error: Problem has too many nonlinear user
754+
# functions. ...", matched on the stable numeric code at the start of
755+
# the message rather than the English text.
756+
with self.assertRaisesRegex(Exception, r"^\?1152"):
757+
self.opt.solve(m)
758+
else:
759+
_solve_and_check(
760+
self,
761+
self.opt,
762+
m,
763+
{
764+
'status': SolutionStatus.feasible,
765+
'objective': 1.0,
766+
'vars': [(m.x, 0.0), (m.y, 0.0)],
767+
},
768+
)
760769

761770
def test_external_function_fgh_callback(self):
762771
"""ExternalFunction with fgh= callback: exercises the _fgh code path in

0 commit comments

Comments
 (0)