source: trunk/test/pyomo/unit/test_misc.py @ 1171

Last change on this file since 1171 was 1171, checked in by wehart, 12 years ago

Various reworks to get _all_ coopr tests passing, at least
when no executables are available.

File size: 1.7 KB
Line 
1#
2# Unit Tests for pyomo.base.misc
3#
4
5import unittest
6import os
7import sys
8from os.path import abspath, dirname
9sys.path.insert(0, dirname(dirname(abspath(__file__)))+os.sep+".."+os.sep+"..")
10currdir= dirname(abspath(__file__))+os.sep
11
12from coopr.pyomo import *
13import pyutilib_th
14
15def rule1(model):
16    return (1,model.x+model.y[1],2)
17def rule2(i,model):
18    return (1,model.x+model.y[1]+i,2)
19
20class PyomoModel(pyutilib_th.TestCase):
21
22    def setUp(self):
23        self.model = Model()
24
25    def test_construct(self):
26        model = Model()
27        model.a = Set(initialize=[1,2,3])
28        model.A = Param(initialize=1)
29        model.B = Param(model.a)
30        model.x = Var(initialize=1,within=Reals)
31        model.y = Var(model.a, initialize=1,within=Reals)
32        model.obj = Objective(rule=lambda model: model.x+model.y[1])
33        model.obj2 = Objective(model.a,rule=lambda i,model: i+model.x+model.y[1])
34        model.con = Constraint(rule=rule1)
35        model.con2 = Constraint(model.a, rule=rule2)
36        instance = model.create()
37        expr = instance.x + 1
38        instance.reset()
39        OUTPUT = open(currdir+"display.out","w")
40        display(instance,ostream=OUTPUT)
41        display(instance.obj,ostream=OUTPUT)
42        display(instance.x,ostream=OUTPUT)
43        display(instance.con,ostream=OUTPUT)
44        expr.pprint(ostream=OUTPUT)
45        model = Model()
46        instance = model.create()
47        display(instance,ostream=OUTPUT)
48        OUTPUT.close()
49        try:
50            display(None)
51            self.fail("test_construct - expected TypeError")
52        except TypeError:
53            pass
54        self.failUnlessFileEqualsBaseline(currdir+"display.out",currdir+"display.txt")
55
56if __name__ == "__main__":
57   unittest.main()
Note: See TracBrowser for help on using the repository browser.