diff --git a/docs/source/conf.py b/docs/source/conf.py index 0cdd12a1..0d8e5176 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -111,9 +111,6 @@ def size_limited_license(): result = True return result - - -size_limited_license = size_limited_license() """ diff --git a/tests/opf/test_graphics.py b/tests/opf/test_graphics.py index e6ba177d..6531bb28 100644 --- a/tests/opf/test_graphics.py +++ b/tests/opf/test_graphics.py @@ -6,8 +6,6 @@ import pathlib import unittest -import gurobipy as gp - from gurobi_optimods.datasets import load_opf_example, load_opf_extra from gurobi_optimods.opf import ( compute_violations, @@ -16,6 +14,8 @@ violation_plot, ) +from ..utils import size_limited_license + # If plotly is not installed, tests will be skipped try: import plotly @@ -23,16 +23,6 @@ plotly = None -def size_limited_license(): - with gp.Env(params={"OutputFlag": 0}) as env, gp.Model(env=env) as model: - model.addVars(2001) - try: - model.optimize() - return False - except gp.GurobiError: - return True - - @unittest.skipIf(plotly is None, "plotly is not installed") class TestGraphicsCase9(unittest.TestCase): def setUp(self): diff --git a/tests/opf/test_solver.py b/tests/opf/test_solver.py index 55495bdd..e2868c41 100644 --- a/tests/opf/test_solver.py +++ b/tests/opf/test_solver.py @@ -4,20 +4,10 @@ import random import unittest -import gurobipy as gp - from gurobi_optimods.datasets import load_opf_example from gurobi_optimods.opf import solve_opf - -def size_limited_license(): - with gp.Env(params={"OutputFlag": 0}) as env, gp.Model(env=env) as model: - model.addVars(2001) - try: - model.optimize() - return False - except gp.GurobiError: - return True +from ..utils import size_limited_license class TestInvalidData(unittest.TestCase): diff --git a/tests/utils.py b/tests/utils.py index ee5a5c8a..bd76da69 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -27,3 +27,20 @@ def skip_wrapper(*args, **kwargs): raise return skip_wrapper + + +def size_limited_license(): + result = False + + try: + import gurobipy as gp + from gurobipy import GRB + + with gp.Env(params={"OutputFlag": 0}) as env, gp.Model(env=env) as model: + x = model.addVars(2001) + model.optimize() + except gp.GurobiError as e: + if e.errno == GRB.Error.SIZE_LIMIT_EXCEEDED: + result = True + + return result