def test_return_value(self): from tinymail.async import start_worker class MyWorker(object): def get_13(self): return 13 try: worker = start_worker(MyWorker()) d = worker.get_13() finally: worker.done() self.assertEqual(d.result, 13)
def test_exception(self): from tinymail.async import start_worker class MyWorker(object): def freak_out(self): raise ValueError('hi') try: worker = start_worker(MyWorker()) d = worker.freak_out() finally: worker.done() self.assertTrue(isinstance(d.result, ValueError)) self.assertEqual(d.result.args, ('hi',))
def test_input_queue(self): called = [] from tinymail.async import start_worker class MyWorker(object): def plus(self, a, b): called.append((a,b)) try: worker = start_worker(MyWorker()) d = worker.plus(3, 4) finally: worker.done() self.assertEqual(called, [(3, 4)])