def test_Next(self): "Additional checks over the main overridden main checks to test pausing and stopping behaviour." class testthread(microprocess): def __init__(self): self.i = 0 self.__super.__init__() def main(self): while 1: self.i = self.i + 1 yield 1 thr = self.init_test(testthread) sched = self.DummySched() thr.activate(sched) for x in vrange(1,5): self.failUnless(thr.next()) self.failUnless(thr.i == x) thr.pause() for x in vrange(5,10): self.failUnless(thr.next()) self.assert_(thr.i == x, "Thread does not pause itself, that is down to the scheduler") thr.unpause() for x in vrange(10,15): self.failUnless(thr.next()) self.failUnless(thr.i == x) thr.stop() self.failIf(thr.next()) self.failUnlessRaises(StopIteration, thr.next)
def test_Next(self): "Additional checks over the main overridden main checks to test pausing and stopping behaviour." class testthread(microprocess): def __init__(self): self.i = 0 self.__super.__init__() def main(self): while 1: self.i = self.i + 1 yield 1 thr = self.init_test(testthread) sched = self.DummySched() thr.activate(sched) for x in vrange(1, 5): self.failUnless(thr.next()) self.failUnless(thr.i == x) thr.pause() for x in vrange(5, 10): self.failUnless(thr.next()) self.assert_( thr.i == x, "Thread does not pause itself, that is down to the scheduler") thr.unpause() for x in vrange(10, 15): self.failUnless(thr.next()) self.failUnless(thr.i == x) thr.stop() self.failIf(thr.next()) self.failUnlessRaises(StopIteration, thr.next)
def test_main_closedowntest(self): """main - This ensures that the closeDownComponent method is called at the end of the loop. It also repeats the above test.""" t=TestMainLoopComponentClosedown() m=t.main() self.failUnless(next(m)==1) for x in vrange(1,1000): self.failUnless(next(m)==x, "Failed when x = " + str(x)) self.failUnlessRaises(closeDownCompTestException , lambda: next(m))#Ensures that the closeDownComponent method has been called. self.failUnlessRaises(StopIteration, lambda: next(m))#, "Checks the generator has finished.")
def test_main_smokeTest(self): """main - Returns a generator that implements the documented behaviour of a highly simplistic approach component statemachine. First value returned is always 1 then the return values are those from the component's main method unitil it returns a False value.""" t=TestMainLoopComponent() m=t.main() self.failUnless(next(m)==1) for x in vrange(1,1000): self.failUnless(next(m)==x, "Failed when x = " + str(x)) self.failUnless(next(m)==1,"After the main method returns a false value the result of closeDownComponent is returned. Stub of 1 assumed.") self.failUnlessRaises(StopIteration, lambda : next(m))#, "Checks the generator has finished.")
def test_main_closedowntest(self): """main - This ensures that the closeDownComponent method is called at the end of the loop. It also repeats the above test.""" t = TestMainLoopComponentClosedown() m = t.main() self.failUnless(next(m) == 1) for x in vrange(1, 1000): self.failUnless(next(m) == x, "Failed when x = " + str(x)) self.failUnlessRaises(closeDownCompTestException, lambda: next( m)) #Ensures that the closeDownComponent method has been called. self.failUnlessRaises( StopIteration, lambda: next(m)) #, "Checks the generator has finished.")
def test_send(self): "send - Takes the message and places it into the specified outbox." tcomp=TComponentAsync() tcomp.tc1.send("ba") self.failUnless(tcomp.tc1.outboxes["outbox"].pop(0)=="ba", "Sent item not put in outbox.") tcomp.tc1.send("bing","signal") tcomp.tc1.send("boom","signal") signalbox = tcomp.tc1.outboxes["signal"] self.failUnless(signalbox.pop(0)=="bing", "Items arrived out of order") self.failUnless(signalbox.pop(0)=="boom", "Items arrived out of order") for x in vrange(0,1000): tcomp.tc1.send(x) self.failUnless(tcomp.tc1.outboxes["outbox"].pop(0)==x, "Failed while sending lots without clearing box.")
def test_main_smokeTest(self): """main - Returns a generator that implements the documented behaviour of a highly simplistic approach component statemachine. First value returned is always 1 then the return values are those from the component's main method unitil it returns a False value.""" t = TestMainLoopComponent() m = t.main() self.failUnless(next(m) == 1) for x in vrange(1, 1000): self.failUnless(next(m) == x, "Failed when x = " + str(x)) self.failUnless( next(m) == 1, "After the main method returns a false value the result of closeDownComponent is returned. Stub of 1 assumed." ) self.failUnlessRaises( StopIteration, lambda: next(m)) #, "Checks the generator has finished.")
def test_send(self): "send - Takes the message and places it into the specified outbox." tcomp = TComponentAsync() tcomp.tc1.send("ba") self.failUnless(tcomp.tc1.outboxes["outbox"].pop(0) == "ba", "Sent item not put in outbox.") tcomp.tc1.send("bing", "signal") tcomp.tc1.send("boom", "signal") signalbox = tcomp.tc1.outboxes["signal"] self.failUnless( signalbox.pop(0) == "bing", "Items arrived out of order") self.failUnless( signalbox.pop(0) == "boom", "Items arrived out of order") for x in vrange(0, 1000): tcomp.tc1.send(x) self.failUnless(tcomp.tc1.outboxes["outbox"].pop(0) == x, "Failed while sending lots without clearing box.")
def test_overriddenMainWorksWithNext(self): "Tests that an overridden main is run correctly by repeatedly calling next() and that termination occurs at the proper time with the proper StopIteration exception." class testthread(microprocess): def __init__(self): self.i = 0 self.__super.__init__() def main(self): while self.i < 100: self.i = self.i + 1 yield 1 thr = self.init_test(testthread) thr.activate(self.DummySched()) for i in vrange(1,101): self.failUnless(thr.next(), "Unexpected false return value") self.failUnless(thr.i == i, "Iteration of main not performed!") #self.failIf(thr.next(), "Should return false as has returned at this point.") self.failUnlessRaises(StopIteration, thr.next) self.failUnless(thr.i == 100, "Unexpected final result of iteration")
def test_overriddenMainWorksWithNext(self): "Tests that an overridden main is run correctly by repeatedly calling next() and that termination occurs at the proper time with the proper StopIteration exception." class testthread(microprocess): def __init__(self): self.i = 0 self.__super.__init__() def main(self): while self.i < 100: self.i = self.i + 1 yield 1 thr = self.init_test(testthread) thr.activate(self.DummySched()) for i in vrange(1, 101): self.failUnless(thr.next(), "Unexpected false return value") self.failUnless(thr.i == i, "Iteration of main not performed!") #self.failIf(thr.next(), "Should return false as has returned at this point.") self.failUnlessRaises(StopIteration, thr.next) self.failUnless(thr.i == 100, "Unexpected final result of iteration")