diff options
| author | Yury Selivanov <yury@magic.io> | 2016-11-04 18:29:28 (GMT) |
|---|---|---|
| committer | Yury Selivanov <yury@magic.io> | 2016-11-04 18:29:28 (GMT) |
| commit | 600a349781bfa0a8239e1cb95fac29c7c4a3302e (patch) | |
| tree | 79f35114de7101a97fe85f80cd02cbd866d4abd9 /Lib/test/test_asyncio/test_base_events.py | |
| parent | 1ea023e523f484955fb81b59a72c586845d8d97f (diff) | |
| download | cpython-600a349781bfa0a8239e1cb95fac29c7c4a3302e.zip cpython-600a349781bfa0a8239e1cb95fac29c7c4a3302e.tar.gz cpython-600a349781bfa0a8239e1cb95fac29c7c4a3302e.tar.bz2 | |
Issue #28613: Fix get_event_loop() to return the current loop
when called from coroutines or callbacks.
Diffstat (limited to 'Lib/test/test_asyncio/test_base_events.py')
| -rw-r--r-- | Lib/test/test_asyncio/test_base_events.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index 3913125..cdbd587 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -154,6 +154,7 @@ class BaseEventTests(test_utils.TestCase): class BaseEventLoopTests(test_utils.TestCase): def setUp(self): + super().setUp() self.loop = base_events.BaseEventLoop() self.loop._selector = mock.Mock() self.loop._selector.select.return_value = () @@ -976,6 +977,7 @@ class MyDatagramProto(asyncio.DatagramProtocol): class BaseEventLoopWithSelectorTests(test_utils.TestCase): def setUp(self): + super().setUp() self.loop = asyncio.new_event_loop() self.set_event_loop(self.loop) @@ -1692,5 +1694,23 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase): "took .* seconds$") +class RunningLoopTests(unittest.TestCase): + + def test_running_loop_within_a_loop(self): + @asyncio.coroutine + def runner(loop): + loop.run_forever() + + loop = asyncio.new_event_loop() + outer_loop = asyncio.new_event_loop() + try: + with self.assertRaisesRegex(RuntimeError, + 'while another loop is running'): + outer_loop.run_until_complete(runner(loop)) + finally: + loop.close() + outer_loop.close() + + if __name__ == '__main__': unittest.main() |
