diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-06-17 23:36:32 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-06-17 23:36:32 (GMT) |
commit | c73701de7292b7de0fee5b7f82a610d7515c18a4 (patch) | |
tree | 18db9589cbd8880f4b1ac411bf675de788740e34 /Lib/test/test_asyncio/test_queues.py | |
parent | d6f02fc649d2e248f2e7b418771371db2b6637a2 (diff) | |
download | cpython-c73701de7292b7de0fee5b7f82a610d7515c18a4.zip cpython-c73701de7292b7de0fee5b7f82a610d7515c18a4.tar.gz cpython-c73701de7292b7de0fee5b7f82a610d7515c18a4.tar.bz2 |
asyncio: Refactor tests: add a base TestCase class
Diffstat (limited to 'Lib/test/test_asyncio/test_queues.py')
-rw-r--r-- | Lib/test/test_asyncio/test_queues.py | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/Lib/test/test_asyncio/test_queues.py b/Lib/test/test_asyncio/test_queues.py index 820234d..32c90f4 100644 --- a/Lib/test/test_asyncio/test_queues.py +++ b/Lib/test/test_asyncio/test_queues.py @@ -7,14 +7,10 @@ import asyncio from asyncio import test_utils -class _QueueTestBase(unittest.TestCase): +class _QueueTestBase(test_utils.TestCase): def setUp(self): - self.loop = test_utils.TestLoop() - asyncio.set_event_loop(None) - - def tearDown(self): - self.loop.close() + self.loop = self.new_test_loop() class QueueBasicTests(_QueueTestBase): @@ -32,8 +28,7 @@ class QueueBasicTests(_QueueTestBase): self.assertAlmostEqual(0.2, when) yield 0.1 - loop = test_utils.TestLoop(gen) - self.addCleanup(loop.close) + loop = self.new_test_loop(gen) q = asyncio.Queue(loop=loop) self.assertTrue(fn(q).startswith('<Queue'), fn(q)) @@ -80,12 +75,9 @@ class QueueBasicTests(_QueueTestBase): self.assertIs(q._loop, self.loop) def test_ctor_noloop(self): - try: - asyncio.set_event_loop(self.loop) - q = asyncio.Queue() - self.assertIs(q._loop, self.loop) - finally: - asyncio.set_event_loop(None) + asyncio.set_event_loop(self.loop) + q = asyncio.Queue() + self.assertIs(q._loop, self.loop) def test_repr(self): self._test_repr_or_str(repr, True) @@ -126,8 +118,7 @@ class QueueBasicTests(_QueueTestBase): self.assertAlmostEqual(0.02, when) yield 0.01 - loop = test_utils.TestLoop(gen) - self.addCleanup(loop.close) + loop = self.new_test_loop(gen) q = asyncio.Queue(maxsize=2, loop=loop) self.assertEqual(2, q.maxsize) @@ -194,8 +185,7 @@ class QueueGetTests(_QueueTestBase): self.assertAlmostEqual(0.01, when) yield 0.01 - loop = test_utils.TestLoop(gen) - self.addCleanup(loop.close) + loop = self.new_test_loop(gen) q = asyncio.Queue(loop=loop) started = asyncio.Event(loop=loop) @@ -241,8 +231,7 @@ class QueueGetTests(_QueueTestBase): self.assertAlmostEqual(0.061, when) yield 0.05 - loop = test_utils.TestLoop(gen) - self.addCleanup(loop.close) + loop = self.new_test_loop(gen) q = asyncio.Queue(loop=loop) @@ -302,8 +291,7 @@ class QueuePutTests(_QueueTestBase): self.assertAlmostEqual(0.01, when) yield 0.01 - loop = test_utils.TestLoop(gen) - self.addCleanup(loop.close) + loop = self.new_test_loop(gen) q = asyncio.Queue(maxsize=1, loop=loop) started = asyncio.Event(loop=loop) |