Example #1
0
 def test_error(self):
     class A(object): pass
     val = A()
     try:
         is_constant(val)
         self.fail("Expected TypeError")
     except TypeError:
         pass
Example #2
0
 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)
Example #3
0
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)
Example #4
0
 def test_const2(self):
     val = NumericConstant('foo')
     self.assertTrue(is_constant(val))
Example #5
0
 def test_const1(self):
     val = NumericConstant(1.0)
     self.assertTrue(is_constant(val))
Example #6
0
 def test_string(self):
     self.assertTrue(is_constant('foo'))
Example #7
0
 def test_long(self):
     val = int(1e10)
     self.assertTrue(is_constant(val))
Example #8
0
 def test_int(self):
     self.assertTrue(is_constant(1))
Example #9
0
 def test_float(self):
     self.assertTrue(is_constant(1.1))
Example #10
0
 def test_bool(self):
     self.assertTrue(is_constant(True))
Example #11
0
 def test_none(self):
     self.assertTrue(is_constant(None))