summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/test_utils.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-17 23:36:32 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-06-17 23:36:32 (GMT)
commitc73701de7292b7de0fee5b7f82a610d7515c18a4 (patch)
tree18db9589cbd8880f4b1ac411bf675de788740e34 /Lib/asyncio/test_utils.py
parentd6f02fc649d2e248f2e7b418771371db2b6637a2 (diff)
downloadcpython-c73701de7292b7de0fee5b7f82a610d7515c18a4.zip
cpython-c73701de7292b7de0fee5b7f82a610d7515c18a4.tar.gz
cpython-c73701de7292b7de0fee5b7f82a610d7515c18a4.tar.bz2
asyncio: Refactor tests: add a base TestCase class
Diffstat (limited to 'Lib/asyncio/test_utils.py')
-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 1062bae..d9c7ae2 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)