Skip to content

Commit 12a257c

Browse files
committed
remove deprecated asyncio.coroutines syntax from tests
tests._testutils.run_until_complete is not referenced anymore since moving to pytest.mark.run_loop in 819d4ec
1 parent 112c11c commit 12a257c

File tree

3 files changed

+39
-61
lines changed

3 files changed

+39
-61
lines changed

tests/_testutils.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,6 @@
11
import asyncio
22
import unittest
33

4-
from functools import wraps
5-
6-
7-
def run_until_complete(fun):
8-
if not asyncio.iscoroutinefunction(fun):
9-
fun = asyncio.coroutine(fun)
10-
11-
@wraps(fun)
12-
def wrapper(test, *args, **kw):
13-
loop = test.loop
14-
ret = loop.run_until_complete(
15-
asyncio.wait_for(fun(test, *args, **kw), 15))
16-
return ret
17-
return wrapper
18-
194

205
class BaseTest(unittest.TestCase):
216
"""Base test case for unittests.

tests/base.py

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
import asyncio
21
import os
32
import aiomysql
43
from tests._testutils import BaseTest
54

65

76
class AIOPyMySQLTestCase(BaseTest):
87

9-
@asyncio.coroutine
10-
def _connect_all(self):
11-
conn1 = yield from aiomysql.connect(loop=self.loop, host=self.host,
12-
port=self.port, user=self.user,
13-
db=self.db,
14-
password=self.password,
15-
use_unicode=True, echo=True)
16-
conn2 = yield from aiomysql.connect(loop=self.loop, host=self.host,
17-
port=self.port, user=self.user,
18-
db=self.other_db,
19-
password=self.password,
20-
use_unicode=False, echo=True)
21-
conn3 = yield from aiomysql.connect(loop=self.loop, host=self.host,
22-
port=self.port, user=self.user,
23-
db=self.db,
24-
password=self.password,
25-
use_unicode=True, echo=True,
26-
local_infile=True)
8+
async def _connect_all(self):
9+
conn1 = await aiomysql.connect(loop=self.loop, host=self.host,
10+
port=self.port, user=self.user,
11+
db=self.db,
12+
password=self.password,
13+
use_unicode=True, echo=True)
14+
conn2 = await aiomysql.connect(loop=self.loop, host=self.host,
15+
port=self.port, user=self.user,
16+
db=self.other_db,
17+
password=self.password,
18+
use_unicode=False, echo=True)
19+
conn3 = await aiomysql.connect(loop=self.loop, host=self.host,
20+
port=self.port, user=self.user,
21+
db=self.db,
22+
password=self.password,
23+
use_unicode=True, echo=True,
24+
local_infile=True)
2725

2826
self.connections = [conn1, conn2, conn3]
2927

@@ -45,9 +43,9 @@ def tearDown(self):
4543
self.doCleanups()
4644
super(AIOPyMySQLTestCase, self).tearDown()
4745

48-
@asyncio.coroutine
49-
def connect(self, host=None, user=None, password=None,
50-
db=None, use_unicode=True, no_delay=None, port=None, **kwargs):
46+
async def connect(self, host=None, user=None, password=None,
47+
db=None, use_unicode=True, no_delay=None, port=None,
48+
**kwargs):
5149
if host is None:
5250
host = self.host
5351
if user is None:
@@ -58,18 +56,17 @@ def connect(self, host=None, user=None, password=None,
5856
db = self.db
5957
if port is None:
6058
port = self.port
61-
conn = yield from aiomysql.connect(loop=self.loop, host=host,
62-
user=user, password=password,
63-
db=db, use_unicode=use_unicode,
64-
no_delay=no_delay, port=port,
65-
**kwargs)
59+
conn = await aiomysql.connect(loop=self.loop, host=host,
60+
user=user, password=password,
61+
db=db, use_unicode=use_unicode,
62+
no_delay=no_delay, port=port,
63+
**kwargs)
6664
self.addCleanup(conn.close)
6765
return conn
6866

69-
@asyncio.coroutine
70-
def create_pool(self, host=None, user=None, password=None,
71-
db=None, use_unicode=True, no_delay=None,
72-
port=None, **kwargs):
67+
async def create_pool(self, host=None, user=None, password=None,
68+
db=None, use_unicode=True, no_delay=None,
69+
port=None, **kwargs):
7370
if host is None:
7471
host = self.host
7572
if user is None:
@@ -80,10 +77,10 @@ def create_pool(self, host=None, user=None, password=None,
8077
db = self.db
8178
if port is None:
8279
port = self.port
83-
pool = yield from aiomysql.create_pool(loop=self.loop, host=host,
84-
user=user, password=password,
85-
db=db, use_unicode=use_unicode,
86-
no_delay=no_delay, port=port,
87-
**kwargs)
80+
pool = await aiomysql.create_pool(loop=self.loop, host=host,
81+
user=user, password=password,
82+
db=db, use_unicode=use_unicode,
83+
no_delay=no_delay, port=port,
84+
**kwargs)
8885
self.addCleanup(pool.close)
8986
return pool

tests/conftest.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ def mysql_params(mysql_server):
112112

113113

114114
# TODO: fix this workaround
115-
@asyncio.coroutine
116-
def _cursor_wrapper(conn):
117-
cur = yield from conn.cursor()
118-
return cur
115+
async def _cursor_wrapper(conn):
116+
return await conn.cursor()
119117

120118

121119
@pytest.fixture
@@ -137,12 +135,11 @@ def connection(mysql_params, loop):
137135
def connection_creator(mysql_params, loop):
138136
connections = []
139137

140-
@asyncio.coroutine
141-
def f(**kw):
138+
async def f(**kw):
142139
conn_kw = mysql_params.copy()
143140
conn_kw.update(kw)
144141
_loop = conn_kw.pop('loop', loop)
145-
conn = yield from aiomysql.connect(loop=_loop, **conn_kw)
142+
conn = await aiomysql.connect(loop=_loop, **conn_kw)
146143
connections.append(conn)
147144
return conn
148145

@@ -159,12 +156,11 @@ def f(**kw):
159156
def pool_creator(mysql_params, loop):
160157
pools = []
161158

162-
@asyncio.coroutine
163-
def f(**kw):
159+
async def f(**kw):
164160
conn_kw = mysql_params.copy()
165161
conn_kw.update(kw)
166162
_loop = conn_kw.pop('loop', loop)
167-
pool = yield from aiomysql.create_pool(loop=_loop, **conn_kw)
163+
pool = await aiomysql.create_pool(loop=_loop, **conn_kw)
168164
pools.append(pool)
169165
return pool
170166

0 commit comments

Comments
 (0)