Ejemplo n.º 1
0
 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")
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
 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")
Ejemplo n.º 4
0
 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")
Ejemplo n.º 5
0
 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")
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 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")
Ejemplo n.º 10
0
 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")
Ejemplo n.º 11
0
 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")
Ejemplo n.º 12
0
 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")