def testRunContext(self): r = Random() n = r.randint(1, 999) c = RunContext(n) t = Task(c.execute) t.run(None) self.assertEqual(n, t.result, "The result and generated random number must be equal")
def testCallbackFail(self): r = Random() n = r.randint(1, 999) c = FailCallback(n) t = Task(c.execute, c.callback) try: t.run(None) self.fail("The expected exception was not thrown") except CallbackExecutionException as e: self.assertEqual("Failure! %i" % n, "%s" % e, "Exception message not correct")
def testErrorFieldSet(self): global errorFunction, result t = Task(errorFunction) try: t.run(None) self.fail("Exception not raised") except: pass self.assertTrue(result, "Function not called") self.assertEqual("Failed", "%s" % t.error, "Error field not set")
def testResultFieldUnset(self): global errorFunction, result t = Task(errorFunction) try: t.run(None) self.fail("Exception not raised") except: pass self.assertTrue(result, "Function not called") self.assertEqual(None, t.result, "Result field set")
def testSuccessfulFlagFalse(self): global errorFunction, result t = Task(errorFunction) try: t.run(None) self.fail("Exception not raised") except: pass self.assertTrue(result, "Function not called") self.assertFalse(t.successful, "Run flag not set")
def testCallbackSuccess(self): r = Random() n = r.randint(1, 999) c = SuccessfulCallback(n) t = Task(c.execute, c.callback) try: t.run(None) self.assertEqual(n, t.result, "The result and generated random number must be equal") self.assertEqual(n, c.result, "The callback-stored result and random number must be equal") self.assertTrue(c.successful, "The callback must set the successful flag") except Exception as e: self.fail("Threw exception: %s" % e)
def testAlreadyRun(self): r = Runner(100) t = Task(r.execute) try: t.run(None) except: self.fail("Exception thrown where unexpected") try: t.run(None) self.fail("Did not cause any exceptions") except AlreadyRunException: pass
def testNoArgsJob(self): # Tests that a job which isn't expecting args still works j = NoArgsJob() t = Task(j.do) t.run(None) self.assertTrue(j.run)
def testResultFieldSet(self): global runFunction, result t = Task(runFunction) t.run(None) self.assertTrue(result, "Function not called") self.assertEqual(True, t.result, "Result field not set")
def testErrorFieldUnset(self): global runFunction, result t = Task(runFunction) t.run(None) self.assertTrue(result, "Function not called") self.assertEqual(None, t.error, "Error field set")
def testSuccessfulFlagTrue(self): global runFunction, result t = Task(runFunction) t.run(None) self.assertTrue(result, "Function not called") self.assertTrue(t.successful, "Run flag not set")
def testRunFlag(self): global runFunction, result t = Task(runFunction) t.run(None) self.assertTrue(result, "Function not called") self.assertTrue(t.hasRun, "Run flag not set")