From 70c552c9de6096ca96b095d03111ade5117a7b17 Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Tue, 28 Jun 2016 18:02:48 -0400 Subject: [PATCH] Fix uvloop tests under 3.5.2 --- tests/test_sockets.py | 6 ++++++ tests/test_tcp.py | 4 ++++ uvloop/_patch.py | 14 +++++--------- uvloop/_testbase.py | 3 +++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/test_sockets.py b/tests/test_sockets.py index 67df78a..e0acfe5 100644 --- a/tests/test_sockets.py +++ b/tests/test_sockets.py @@ -1,5 +1,7 @@ import asyncio import socket +import sys +import unittest from uvloop import _testbase as tb @@ -16,6 +18,10 @@ class _TestSockets: return buf def test_socket_connect_recv_send(self): + if self.is_asyncio_loop() and sys.version_info[:3] == (3, 5, 2): + # See https://github.com/python/asyncio/pull/366 for details. + raise unittest.SkipTest() + def srv_gen(): yield tb.write(b'helo') data = yield tb.read(4 * _SIZE) diff --git a/tests/test_tcp.py b/tests/test_tcp.py index 42b6203..47aefd1 100644 --- a/tests/test_tcp.py +++ b/tests/test_tcp.py @@ -9,6 +9,10 @@ from uvloop import _testbase as tb class _TestTCP: def test_create_server_1(self): + if self.is_asyncio_loop() and sys.version_info[:3] == (3, 5, 2): + # See https://github.com/python/asyncio/pull/366 for details. + raise unittest.SkipTest() + CNT = 0 # number of clients that were successful TOTAL_CNT = 25 # total number of clients that test will create TIMEOUT = 5.0 # timeout for this test diff --git a/uvloop/_patch.py b/uvloop/_patch.py index 60d3ce2..c631b5a 100644 --- a/uvloop/_patch.py +++ b/uvloop/_patch.py @@ -1,3 +1,4 @@ +import asyncio import sys @@ -55,20 +56,15 @@ async def _wait_for_data(self, func_name): self._waiter = None -if sys.version_info < (3, 5, 2): - # In Python 3.5.2 (see PEP 478 for 3.5 release schedule) - # we won't need to patch anything. - - import asyncio - - from asyncio import coroutines - from asyncio import streams - +if sys.version_info < (3, 5, 3): # This is needed to support Cython 'async def' coroutines. + from asyncio import coroutines _old_format_coroutine = coroutines._format_coroutine coroutines._format_coroutine = _format_coroutine +if sys.version_info < (3, 5, 2): # Fix a possible deadlock, improve performance. + from asyncio import streams _old_wait_for_data = streams.StreamReader._wait_for_data _wait_for_data.__module__ = _old_wait_for_data.__module__ streams.StreamReader._wait_for_data = _wait_for_data diff --git a/uvloop/_testbase.py b/uvloop/_testbase.py index 0a79c41..c4be2fe 100644 --- a/uvloop/_testbase.py +++ b/uvloop/_testbase.py @@ -63,6 +63,9 @@ class BaseTestCase(unittest.TestCase, metaclass=BaseTestCaseMeta): def mock_pattern(self, str): return MockPattern(str) + def is_asyncio_loop(self): + return type(self.loop).__module__.startswith('asyncio.') + def setUp(self): self.loop = self.new_loop() asyncio.set_event_loop(self.loop)