def test_wrap_greenlet_exc(self): def func(): raise ValueError(7) gl = greenlet.greenlet(func) fut = aiogevent.wrap_greenlet(gl) gl.switch() self.assertRaises(ValueError, self.loop.run_until_complete, fut)
def test_wrap_greenlet(self): def func(value): return value * 3 gl = greenlet.greenlet(func) fut = aiogevent.wrap_greenlet(gl) gl.switch(5) result = self.loop.run_until_complete(fut) self.assertEqual(result, 15)
def func(): try: gt = gevent.getcurrent() fut = aiogevent.wrap_greenlet(gt) except Exception as exc: result.append((True, exc)) else: result.append((False, fut)) event.set()
def test_wrap_greenlet_exc(self): self.loop.set_debug(True) def func(): raise ValueError(7) gt = gevent.spawn_raw(func) fut = aiogevent.wrap_greenlet(gt) self.assertRaises(ValueError, self.loop.run_until_complete, fut)
def test_wrap_greenlet(self): def func(): gevent.sleep(0.010) return "ok" gt = gevent.spawn_raw(func) fut = aiogevent.wrap_greenlet(gt) result = self.loop.run_until_complete(fut) self.assertEqual(result, "ok")
def coro_wrap_greenlet(): result = [] gt = gevent.spawn(gevent_slow_append, result, 1, 0.020) value = yield From(aiogevent.wrap_greenlet(gt)) result.append(value) gt = gevent.spawn(gevent_slow_append, result, 2, 0.010) value = yield From(aiogevent.wrap_greenlet(gt)) result.append(value) gt = gevent.spawn(gevent_slow_error) try: yield From(aiogevent.wrap_greenlet(gt)) except ValueError as exc: result.append(str(exc)) result.append(4) raise Return(result)
def test_wrap_greenlet_exc(self): self.loop.set_debug(True) def func(): raise ValueError(7) # FIXME: the unit test must fail!? with tests.mock.patch('traceback.print_exception') as print_exception: gt = gevent.spawn(func) fut = aiogevent.wrap_greenlet(gt) self.assertRaises(ValueError, self.loop.run_until_complete, fut) # the exception must not be logger by traceback: the caller must # consume the exception from the future object self.assertFalse(print_exception.called)
def func(value): gl = greenlet.getcurrent() return aiogevent.wrap_greenlet(gl)
def func(): return aiogevent.wrap_greenlet(gt)