Skip to content

Commit

Permalink
remove deprecated asyncio.coroutines syntax from tests
Browse files Browse the repository at this point in the history
tests._testutils.run_until_complete is not referenced anymore since moving to pytest.mark.run_loop in 819d4ec
  • Loading branch information
Nothing4You committed Jan 26, 2022
1 parent 6887375 commit 87e0f56
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 61 deletions.
15 changes: 0 additions & 15 deletions tests/_testutils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import asyncio
import unittest

from functools import wraps


def run_until_complete(fun):
if not asyncio.iscoroutinefunction(fun):
fun = asyncio.coroutine(fun)

@wraps(fun)
def wrapper(test, *args, **kw):
loop = test.loop
ret = loop.run_until_complete(
asyncio.wait_for(fun(test, *args, **kw), 15))
return ret
return wrapper


class BaseTest(unittest.TestCase):
"""Base test case for unittests.
Expand Down
69 changes: 33 additions & 36 deletions tests/base.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import asyncio
import os
import aiomysql
from tests._testutils import BaseTest


class AIOPyMySQLTestCase(BaseTest):

@asyncio.coroutine
def _connect_all(self):
conn1 = yield from aiomysql.connect(loop=self.loop, host=self.host,
port=self.port, user=self.user,
db=self.db,
password=self.password,
use_unicode=True, echo=True)
conn2 = yield from aiomysql.connect(loop=self.loop, host=self.host,
port=self.port, user=self.user,
db=self.other_db,
password=self.password,
use_unicode=False, echo=True)
conn3 = yield from aiomysql.connect(loop=self.loop, host=self.host,
port=self.port, user=self.user,
db=self.db,
password=self.password,
use_unicode=True, echo=True,
local_infile=True)
async def _connect_all(self):
conn1 = await aiomysql.connect(loop=self.loop, host=self.host,
port=self.port, user=self.user,
db=self.db,
password=self.password,
use_unicode=True, echo=True)
conn2 = await aiomysql.connect(loop=self.loop, host=self.host,
port=self.port, user=self.user,
db=self.other_db,
password=self.password,
use_unicode=False, echo=True)
conn3 = await aiomysql.connect(loop=self.loop, host=self.host,
port=self.port, user=self.user,
db=self.db,
password=self.password,
use_unicode=True, echo=True,
local_infile=True)

self.connections = [conn1, conn2, conn3]

Expand All @@ -45,9 +43,9 @@ def tearDown(self):
self.doCleanups()
super(AIOPyMySQLTestCase, self).tearDown()

@asyncio.coroutine
def connect(self, host=None, user=None, password=None,
db=None, use_unicode=True, no_delay=None, port=None, **kwargs):
async def connect(self, host=None, user=None, password=None,
db=None, use_unicode=True, no_delay=None, port=None,
**kwargs):
if host is None:
host = self.host
if user is None:
Expand All @@ -58,18 +56,17 @@ def connect(self, host=None, user=None, password=None,
db = self.db
if port is None:
port = self.port
conn = yield from aiomysql.connect(loop=self.loop, host=host,
user=user, password=password,
db=db, use_unicode=use_unicode,
no_delay=no_delay, port=port,
**kwargs)
conn = await aiomysql.connect(loop=self.loop, host=host,
user=user, password=password,
db=db, use_unicode=use_unicode,
no_delay=no_delay, port=port,
**kwargs)
self.addCleanup(conn.close)
return conn

@asyncio.coroutine
def create_pool(self, host=None, user=None, password=None,
db=None, use_unicode=True, no_delay=None,
port=None, **kwargs):
async def create_pool(self, host=None, user=None, password=None,
db=None, use_unicode=True, no_delay=None,
port=None, **kwargs):
if host is None:
host = self.host
if user is None:
Expand All @@ -80,10 +77,10 @@ def create_pool(self, host=None, user=None, password=None,
db = self.db
if port is None:
port = self.port
pool = yield from aiomysql.create_pool(loop=self.loop, host=host,
user=user, password=password,
db=db, use_unicode=use_unicode,
no_delay=no_delay, port=port,
**kwargs)
pool = await aiomysql.create_pool(loop=self.loop, host=host,
user=user, password=password,
db=db, use_unicode=use_unicode,
no_delay=no_delay, port=port,
**kwargs)
self.addCleanup(pool.close)
return pool
16 changes: 6 additions & 10 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ def mysql_params(mysql_server):


# TODO: fix this workaround
@asyncio.coroutine
def _cursor_wrapper(conn):
cur = yield from conn.cursor()
return cur
async def _cursor_wrapper(conn):
return await conn.cursor()


@pytest.fixture
Expand All @@ -137,12 +135,11 @@ def connection(mysql_params, loop):
def connection_creator(mysql_params, loop):
connections = []

@asyncio.coroutine
def f(**kw):
async def f(**kw):
conn_kw = mysql_params.copy()
conn_kw.update(kw)
_loop = conn_kw.pop('loop', loop)
conn = yield from aiomysql.connect(loop=_loop, **conn_kw)
conn = await aiomysql.connect(loop=_loop, **conn_kw)
connections.append(conn)
return conn

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

@asyncio.coroutine
def f(**kw):
async def f(**kw):
conn_kw = mysql_params.copy()
conn_kw.update(kw)
_loop = conn_kw.pop('loop', loop)
pool = yield from aiomysql.create_pool(loop=_loop, **conn_kw)
pool = await aiomysql.create_pool(loop=_loop, **conn_kw)
pools.append(pool)
return pool

Expand Down

0 comments on commit 87e0f56

Please sign in to comment.