diff --git a/pyomo/core/tests/unit/test_initializer.py b/pyomo/core/tests/unit/test_initializer.py index 5767406bdf7..b334a6b857b 100644 --- a/pyomo/core/tests/unit/test_initializer.py +++ b/pyomo/core/tests/unit/test_initializer.py @@ -11,6 +11,8 @@ import functools import pickle +import platform +import sys import types import pyomo.common.unittest as unittest @@ -37,6 +39,9 @@ from pyomo.environ import ConcreteModel, Var +is_pypy = platform.python_implementation().lower().startswith("pypy") + + def _init_scalar(m): return 1 @@ -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' diff --git a/pyomo/core/tests/unit/test_pickle.py b/pyomo/core/tests/unit/test_pickle.py index 808db2e45f3..861704a2f9c 100644 --- a/pyomo/core/tests/unit/test_pickle.py +++ b/pyomo/core/tests/unit/test_pickle.py @@ -35,7 +35,7 @@ ) -using_pypy = platform.python_implementation() == "PyPy" +is_pypy = platform.python_implementation().lower().startswith("pypy") def obj_rule(model): @@ -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: