예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
 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()
예제 #4
0
    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)
예제 #5
0
    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")
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
 def func(value):
     gl = greenlet.getcurrent()
     return aiogevent.wrap_greenlet(gl)
예제 #9
0
 def func():
     return aiogevent.wrap_greenlet(gt)