summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2016-09-09 21:26:31 (GMT)
committerGuido van Rossum <guido@python.org>2016-09-09 21:26:31 (GMT)
commit7b3b3dc85da3ec176d7fd7caa546298c232c9c0a (patch)
tree045958462b64c3f8c393c3cc05131c03ceb43aef /Lib/test
parent9b32bda851c113cf4a85cdc01c603a1daba4d5d4 (diff)
downloadcpython-7b3b3dc85da3ec176d7fd7caa546298c232c9c0a.zip
cpython-7b3b3dc85da3ec176d7fd7caa546298c232c9c0a.tar.gz
cpython-7b3b3dc85da3ec176d7fd7caa546298c232c9c0a.tar.bz2
Merge asyncio upstream.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_asyncio/test_events.py2
-rw-r--r--Lib/test/test_asyncio/test_futures.py68
2 files changed, 69 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index e742eb7..7c901f2 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -793,7 +793,7 @@ class EventLoopTestsMixin:
loop.connect_accepted_socket(
(lambda : proto), conn, ssl=server_ssl))
loop.run_forever()
- conn.close()
+ proto.transport.close()
lsock.close()
thread.join(1)
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index c38c1f2..d20eb68 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -25,6 +25,74 @@ def last_cb():
pass
+class DuckFuture:
+ # Class that does not inherit from Future but aims to be duck-type
+ # compatible with it.
+
+ _asyncio_future_blocking = False
+ __cancelled = False
+ __result = None
+ __exception = None
+
+ def cancel(self):
+ if self.done():
+ return False
+ self.__cancelled = True
+ return True
+
+ def cancelled(self):
+ return self.__cancelled
+
+ def done(self):
+ return (self.__cancelled
+ or self.__result is not None
+ or self.__exception is not None)
+
+ def result(self):
+ assert not self.cancelled()
+ if self.__exception is not None:
+ raise self.__exception
+ return self.__result
+
+ def exception(self):
+ assert not self.cancelled()
+ return self.__exception
+
+ def set_result(self, result):
+ assert not self.done()
+ assert result is not None
+ self.__result = result
+
+ def set_exception(self, exception):
+ assert not self.done()
+ assert exception is not None
+ self.__exception = exception
+
+ def __iter__(self):
+ if not self.done():
+ self._asyncio_future_blocking = True
+ yield self
+ assert self.done()
+ return self.result()
+
+
+class DuckTests(test_utils.TestCase):
+
+ def setUp(self):
+ self.loop = self.new_test_loop()
+ self.addCleanup(self.loop.close)
+
+ def test_wrap_future(self):
+ f = DuckFuture()
+ g = asyncio.wrap_future(f)
+ assert g is f
+
+ def test_ensure_future(self):
+ f = DuckFuture()
+ g = asyncio.ensure_future(f)
+ assert g is f
+
+
class FutureTests(test_utils.TestCase):
def setUp(self):