Home | Trees | Indices | Help |
---|
|
1 #!/usr / bin / env python 2 # coding=utf-8 3 from SimPy.Simulation import * 4 from SimPy.MonitorTest import * 5 import unittest 6 # $Revision: 414 $ $Date: 2010-03-26 07:29:21 +0100 (Fri, 26 Mar 2010) $ 7 """testSimPy_simident.py 8 SimPy version 2.1 9 Unit tests of checks of correct use of sim parameter. 10 2.1 introduces checks that two entities involved in a yield (e.g. 11 a Process and a Resource) belong to the same Simulation instance. 12 13 NOTE: This unit test set only works if __debug__ == True. If 14 Python is called with the -O or -OO parameter, the checks are not 15 being executed. 16 17 #'$Revision: 414 $ $Date: 2010-03-26 07:29:21 +0100 (Fri, 26 Mar 2010) $ kgm' 18 19 """ 20 21 simulationVersion=version 22 print "Under test: Simulation.py %s"%simulationVersion 23 __version__ = '2.1 $Revision: 414 $ $Date: 2010-03-26 07:29:21 +0100 (Fri, 26 Mar 2010) $ ' 24 print 'testSimpy_simident.py %s'%__version__ 25 if not __debug__: 26 print "Unit tests not executed -- run in __debug__ mode." 27 sys.exit() 28 34 40 46 52 58 64 70 7678 """Tests of checks for identical sim parameters. 79 """ 80 ## ------------------------------------------------------------- 81 ## Test of "activate" call 82 ## -------------------------------------------------------------20584 s = Simulation() 85 s.initialize() 86 r = Activatetest(sim=s) 87 try: 88 activate(r,r.run()) ## missing s. 89 except FatalSimerror: 90 pass 91 else: 92 self.fail("expected FatalSimerror") 93 s.simulate(until=1)94 95 ## ------------------------------------------------------------- 96 ## Test of "yield request,self,res" 97 ## -------------------------------------------------------------99 s = Simulation() 100 s.initialize() 101 res = Resource( ) # wrong sim 102 r = Requesttest(sim=s) 103 s.activate(r,r.run(res = res)) 104 try: 105 s.simulate(until=1) 106 except FatalSimerror: 107 pass 108 else: 109 self.fail("expected FatalSimerror")110 111 ## ------------------------------------------------------------- 112 ## Test of "yield put,self,store" 113 ## -------------------------------------------------------------115 s = Simulation() 116 s.initialize() 117 store = Store( ) # wrong sim 118 r = PutStoretest(sim=s) 119 s.activate(r,r.run(store = store)) 120 try: 121 s.simulate(until=1) 122 except FatalSimerror: 123 pass 124 else: 125 self.fail("expected FatalSimerror")126 ## ------------------------------------------------------------- 127 ## Test of "yield put,self,level" 128 ## -------------------------------------------------------------130 s = Simulation() 131 s.initialize() 132 levl = Level( ) # wrong sim 133 r = PutLeveltest(sim=s) 134 s.activate(r,r.run(level = levl)) 135 try: 136 s.simulate(until=1) 137 except FatalSimerror: 138 pass 139 else: 140 self.fail("expected FatalSimerror")141 142 ## ------------------------------------------------------------- 143 ## Test of "yield get,self,store" 144 ## -------------------------------------------------------------146 s = Simulation() 147 s.initialize() 148 store = Store( ) # wrong sim 149 r = GetStoretest(sim=s) 150 s.activate(r,r.run(store = store)) 151 try: 152 s.simulate(until=1) 153 except FatalSimerror: 154 pass 155 else: 156 self.fail("expected FatalSimerror")157 158 ## ------------------------------------------------------------- 159 ## Test of "yield get,self,level" 160 ## -------------------------------------------------------------162 s = Simulation() 163 s.initialize() 164 levl = Level( ) # wrong sim 165 r = GetLeveltest(sim=s) 166 s.activate(r,r.run(level = levl)) 167 try: 168 s.simulate(until=1) 169 except FatalSimerror: 170 pass 171 else: 172 self.fail("expected FatalSimerror")173 174 ## ------------------------------------------------------------- 175 ## Test of "yield waitevent,self,evt" 176 ## -------------------------------------------------------------178 s = Simulation() 179 s.initialize() 180 evt = SimEvent() ## wrong sim 181 w = Waiteventtest(sim = s) 182 s.activate(w,w.run(event = evt)) 183 try: 184 s.simulate(until=1) 185 except FatalSimerror: 186 pass 187 else: 188 self.fail("expected FatalSimerror")189 190 ## ------------------------------------------------------------- 191 ## Test of "yield queueevent,self,evt" 192 ## -------------------------------------------------------------194 s = Simulation() 195 s.initialize() 196 evt = SimEvent() ## wrong sim 197 w = Queueeventtest(sim = s) 198 s.activate(w,w.run(event = evt)) 199 try: 200 s.simulate(until=1) 201 except FatalSimerror: 202 pass 203 else: 204 self.fail("expected FatalSimerror")207 suite = unittest.TestSuite() 208 testRequest = makesimtestcase('testRequest') 209 testActivate = makesimtestcase('testActivate') 210 testPutStore = makesimtestcase('testPutStore') 211 testPutLevel = makesimtestcase('testPutLevel') 212 testGetStore = makesimtestcase('testGetStore') 213 testGetLevel = makesimtestcase('testGetLevel') 214 testWaitevent = makesimtestcase('testWaitevent') 215 testQueueevent = makesimtestcase('testQueueevent') 216 217 suite.addTests([testRequest, testActivate, testPutStore, testPutLevel, 218 testGetStore, testGetLevel, testWaitevent, testQueueevent]) 219 return suite220 221 if __name__ == '__main__': 222 alltests = unittest.TestSuite((makesimSuite() 223 )) 224 runner = unittest.TextTestRunner() 225 runner.run(alltests) 226
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue May 11 13:55:16 2010 | http://epydoc.sourceforge.net |