Skip to content

Commit 4dfc9e9

Browse files
committed
Proper fix for Python 3.5
1 parent a8cf78c commit 4dfc9e9

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

tests/test_pool.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import platform
1313
import random
1414
import sys
15+
import textwrap
1516
import time
1617
import unittest
1718

@@ -676,35 +677,41 @@ async def test_pool_handles_transaction_exit_in_asyncgen_1(self):
676677
pool = await self.create_pool(database='postgres',
677678
min_size=1, max_size=1)
678679

679-
async def iterate(con):
680-
async with con.transaction():
681-
for record in await con.fetch("SELECT 1"):
682-
yield record
680+
locals_ = {}
681+
exec(textwrap.dedent('''\
682+
async def iterate(con):
683+
async with con.transaction():
684+
for record in await con.fetch("SELECT 1"):
685+
yield record
686+
'''), globals(), locals_)
683687

684688
class MyException(Exception):
685689
pass
686690

687691
with self.assertRaises(MyException):
688692
async with pool.acquire() as con:
689-
async for _ in iterate(con): # noqa
693+
async for _ in locals_['iterate'](con): # noqa
690694
raise MyException()
691695

692696
@unittest.skipIf(sys.version_info[:2] < (3, 6), 'no asyncgen support')
693697
async def test_pool_handles_transaction_exit_in_asyncgen_2(self):
694698
pool = await self.create_pool(database='postgres',
695699
min_size=1, max_size=1)
696700

697-
async def iterate(con):
698-
async with con.transaction():
699-
for record in await con.fetch("SELECT 1"):
700-
yield record
701+
locals_ = {}
702+
exec(textwrap.dedent('''\
703+
async def iterate(con):
704+
async with con.transaction():
705+
for record in await con.fetch("SELECT 1"):
706+
yield record
707+
'''), globals(), locals_)
701708

702709
class MyException(Exception):
703710
pass
704711

705712
with self.assertRaises(MyException):
706713
async with pool.acquire() as con:
707-
iterator = iterate(con)
714+
iterator = locals_['iterate'](con)
708715
async for _ in iterator: # noqa
709716
raise MyException()
710717

@@ -715,17 +722,20 @@ async def test_pool_handles_asyncgen_finalization(self):
715722
pool = await self.create_pool(database='postgres',
716723
min_size=1, max_size=1)
717724

718-
async def iterate(con):
719-
for record in await con.fetch("SELECT 1"):
720-
yield record
725+
locals_ = {}
726+
exec(textwrap.dedent('''\
727+
async def iterate(con):
728+
for record in await con.fetch("SELECT 1"):
729+
yield record
730+
'''), globals(), locals_)
721731

722732
class MyException(Exception):
723733
pass
724734

725735
with self.assertRaises(MyException):
726736
async with pool.acquire() as con:
727737
async with con.transaction():
728-
async for _ in iterate(con): # noqa
738+
async for _ in locals_['iterate'](con): # noqa
729739
raise MyException()
730740

731741

0 commit comments

Comments
 (0)