Skip to content

Commit

Permalink
Merge branch 'main' into benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bernalde authored Jan 11, 2024
2 parents 09bda47 + a53bebc commit 767da46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions pyomo/core/tests/unit/test_initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import functools
import pickle
import platform
import sys
import types

import pyomo.common.unittest as unittest
Expand All @@ -37,6 +39,9 @@
from pyomo.environ import ConcreteModel, Var


is_pypy = platform.python_implementation().lower().startswith("pypy")


def _init_scalar(m):
return 1

Expand Down Expand Up @@ -561,12 +566,20 @@ def test_no_argspec(self):
self.assertFalse(a.contains_indices())
self.assertEqual(a('111', 2), 7)

# Special case: getfullargspec fails on int, so we assume it is
# always an IndexedCallInitializer
# Special case: getfullargspec fails for int under CPython and
# PyPy<7.3.14, so we assume it is an IndexedCallInitializer.
basetwo = functools.partial(int, '101', base=2)
a = Initializer(basetwo)
self.assertIs(type(a), IndexedCallInitializer)
self.assertFalse(a.constant())
if is_pypy and sys.pypy_version_info[:3] >= (7, 3, 14):
# PyPy behavior diverged from CPython in 7.3.14. Arguably
# this is "more correct", so we will allow the difference to
# persist through Pyomo's Initializer handling (and not
# special case it there)
self.assertIs(type(a), ScalarCallInitializer)
self.assertTrue(a.constant())
else:
self.assertIs(type(a), IndexedCallInitializer)
self.assertFalse(a.constant())
self.assertFalse(a.verified)
self.assertFalse(a.contains_indices())
# but this is not callable, as int won't accept the 'model'
Expand Down
4 changes: 2 additions & 2 deletions pyomo/core/tests/unit/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
)


using_pypy = platform.python_implementation() == "PyPy"
is_pypy = platform.python_implementation().lower().startswith("pypy")


def obj_rule(model):
Expand Down Expand Up @@ -322,7 +322,7 @@ def rule2(model, i):
model.con = Constraint(rule=rule1)
model.con2 = Constraint(model.a, rule=rule2)
instance = model.create_instance()
if using_pypy:
if is_pypy:
str_ = pickle.dumps(instance)
tmp_ = pickle.loads(str_)
else:
Expand Down

0 comments on commit 767da46

Please sign in to comment.