summaryrefslogtreecommitdiff
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-18 01:36:32 +0200
committerVictor Stinner <victor.stinner@gmail.com>2014-06-18 01:36:32 +0200
commitb0aa2b5eb9b528fcb7d9af9ce42d3dce6fe41f19 (patch)
treea7f5c7345761ebb2962c5d961e0622691a1bfd1b /Lib/asyncio
parentf9b74a7d26c044aba53b3f56cb2d9459397ebbd7 (diff)
downloadcpython-b0aa2b5eb9b528fcb7d9af9ce42d3dce6fe41f19.tar.gz
asyncio: Refactor tests: add a base TestCase class
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/test_utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/asyncio/test_utils.py b/Lib/asyncio/test_utils.py
index 1062bae132..d9c7ae2d11 100644
--- a/Lib/asyncio/test_utils.py
+++ b/Lib/asyncio/test_utils.py
@@ -11,6 +11,7 @@ import sys
import tempfile
import threading
import time
+import unittest
from unittest import mock
from http.server import HTTPServer
@@ -379,3 +380,20 @@ def get_function_source(func):
if source is None:
raise ValueError("unable to get the source of %r" % (func,))
return source
+
+
+class TestCase(unittest.TestCase):
+ def set_event_loop(self, loop, *, cleanup=True):
+ assert loop is not None
+ # ensure that the event loop is passed explicitly in asyncio
+ events.set_event_loop(None)
+ if cleanup:
+ self.addCleanup(loop.close)
+
+ def new_test_loop(self, gen=None):
+ loop = TestLoop(gen)
+ self.set_event_loop(loop)
+ return loop
+
+ def tearDown(self):
+ events.set_event_loop(None)