예제 #1
0
파일: test_worker.py 프로젝트: iffy/garden
 def test_receiverMapping(self):
     """
     Should receive IWork, and that's it.
     """
     worker = ThreadedWorker()
     mapping = worker.receiverMapping()
     self.assertEqual(mapping[IWork], worker.workReceived)
예제 #2
0
파일: test_worker.py 프로젝트: iffy/garden
 def test_workReceived(self):
     """
     Should run the work in a thread
     """
     receiver = FakeReceiver([IResult])
     
     w = ThreadedWorker()
     ISource(w).subscribe(receiver)
     
     def foo(a, b):
         return a + b
     w.registerFunction('foo', 'version1', foo)
     
     work = Work('bob', 'foo', 'version1', 'aaaa', [
         ('a', 'v1', 'xxxx', 'big', 'BIG'),
         ('b', 'v1', 'xxxx', 'fish', 'FISH'),
     ])
     yield w.workReceived(work)
     receiver.receive.assert_called_once_with(work.toResult('bigfish'))
예제 #3
0
파일: test_worker.py 프로젝트: iffy/garden
 def test_workReceived_error(self):
     """
     If there's an error doing the work, tell the result_receiver
     """
     receiver = FakeReceiver([IResultError])
     
     w = ThreadedWorker()
     ISource(w).subscribe(receiver)
     
     exc = Exception('foo')
     
     def foo(a):
         raise exc
     w.registerFunction('foo', 'v1', foo)
     
     work = Work('bob', 'foo', 'v1', 'xxxx', [
         ('a', 'v1', 'xxxx', 'big', 'BIG'),
     ])
     yield w.workReceived(work)
     receiver.receive.assert_called_once_with(work.toResultError(repr(exc)))