Skip to content

Commit

Permalink
Unify approach to size limited skips (#147)
Browse files Browse the repository at this point in the history
- Provide a utility function in unit tests
- Use the same check in doctests and unittests
  • Loading branch information
simonbowly committed Jun 21, 2024
1 parent a427d58 commit b590e76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
3 changes: 0 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ def size_limited_license():
result = True
return result
size_limited_license = size_limited_license()
"""


Expand Down
14 changes: 2 additions & 12 deletions tests/opf/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -16,23 +14,15 @@
violation_plot,
)

from ..utils import size_limited_license

# If plotly is not installed, tests will be skipped
try:
import plotly
except ImportError:
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):
Expand Down
12 changes: 1 addition & 11 deletions tests/opf/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b590e76

Please sign in to comment.