def test_error(self): class A(object): pass val = A() try: is_constant(val) self.fail("Expected TypeError") except TypeError: pass
def test_unknownNumericType(self): ref = MyBogusNumericType(42) self.assertTrue(is_constant(ref)) from pyomo.core.base.numvalue import native_numeric_types, native_types self.assertIn(MyBogusNumericType, native_numeric_types) self.assertIn(MyBogusNumericType, native_types) native_numeric_types.remove(MyBogusNumericType) native_types.remove(MyBogusNumericType)
def wrap_var(obj): """ Provides a Wrapper around the obj if it is not a constant value; otherwise, returns the constant value. """ if pe.is_constant(obj): return pe.value(obj) else: return Wrapper(obj)
def test_const2(self): val = NumericConstant('foo') self.assertTrue(is_constant(val))
def test_const1(self): val = NumericConstant(1.0) self.assertTrue(is_constant(val))
def test_string(self): self.assertTrue(is_constant('foo'))
def test_long(self): val = int(1e10) self.assertTrue(is_constant(val))
def test_int(self): self.assertTrue(is_constant(1))
def test_float(self): self.assertTrue(is_constant(1.1))
def test_bool(self): self.assertTrue(is_constant(True))
def test_none(self): self.assertTrue(is_constant(None))