예제 #1
0
 def test_wrap_future_cancel(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(f1.cancelled())
     self.assertTrue(f2.cancelled())
예제 #2
0
 def test_wrap_future_cancel(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertTrue(f1.cancelled())
     self.assertTrue(f2.cancelled())
예제 #3
0
 def test_wrap_future_use_global_loop(self, m_events):
     def run(arg):
         return (arg, get_thread_ident())
     ex = concurrent.futures.ThreadPoolExecutor(1)
     f1 = ex.submit(run, 'oi')
     f2 = asyncio.wrap_future(f1)
     self.assertIs(m_events.get_event_loop.return_value, f2._loop)
예제 #4
0
    def test_wrap_future_use_global_loop(self, m_events):
        def run(arg):
            return (arg, get_thread_ident())

        ex = concurrent.futures.ThreadPoolExecutor(1)
        f1 = ex.submit(run, 'oi')
        f2 = asyncio.wrap_future(f1)
        self.assertIs(m_events.get_event_loop.return_value, f2._loop)
예제 #5
0
 def test_wrap_future_cancel2(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f1.set_result(42)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertFalse(f1.cancelled())
     self.assertEqual(f1.result(), 42)
     self.assertTrue(f2.cancelled())
예제 #6
0
 def test_wrap_future_cancel2(self):
     f1 = concurrent.futures.Future()
     f2 = asyncio.wrap_future(f1, loop=self.loop)
     f1.set_result(42)
     f2.cancel()
     test_utils.run_briefly(self.loop)
     self.assertFalse(f1.cancelled())
     self.assertEqual(f1.result(), 42)
     self.assertTrue(f2.cancelled())
예제 #7
0
    def test_wrap_future(self):
        def run(arg):
            return (arg, get_thread_ident())

        ex = concurrent.futures.ThreadPoolExecutor(1)
        f1 = ex.submit(run, 'oi')
        f2 = asyncio.wrap_future(f1, loop=self.loop)
        res, ident = self.loop.run_until_complete(f2)
        self.assertIsInstance(f2, asyncio.Future)
        self.assertEqual(res, 'oi')
        self.assertNotEqual(ident, get_thread_ident())
예제 #8
0
    def test_wrap_future(self):
        def run(arg):
            return (arg, get_thread_ident())

        ex = concurrent.futures.ThreadPoolExecutor(1)
        f1 = ex.submit(run, "oi")
        f2 = asyncio.wrap_future(f1, loop=self.loop)
        res, ident = self.loop.run_until_complete(f2)
        self.assertIsInstance(f2, asyncio.Future)
        self.assertEqual(res, "oi")
        self.assertNotEqual(ident, get_thread_ident())
예제 #9
0
 def test_wrap_future_future(self):
     f1 = asyncio.Future(loop=self.loop)
     f2 = asyncio.wrap_future(f1)
     self.assertIs(f1, f2)
예제 #10
0
 def test_wrap_future_future(self):
     f1 = asyncio.Future(loop=self.loop)
     f2 = asyncio.wrap_future(f1)
     self.assertIs(f1, f2)
예제 #11
0
 def test_wrap_future(self):
     fut = asyncio.Future()
     self.assertIs(trollius.wrap_future(fut), fut)