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