Skip to content

Commit 75f3f3c

Browse files
committed
Fix syntax_async.py for 3.11
1 parent 8c38a83 commit 75f3f3c

File tree

1 file changed

+42
-35
lines changed

1 file changed

+42
-35
lines changed

extra_tests/snippets/syntax_async.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import sys
12
import asyncio
23
import unittest
34

5+
46
class ContextManager:
57
async def __aenter__(self):
68
print("Entrada")
@@ -41,15 +43,18 @@ async def a(s, m):
4143
async for i in AIterWrap(range(0, 2)):
4244
print(i)
4345
ls.append(m)
44-
await asyncio.sleep(1)
46+
await asyncio.sleep(0.1)
47+
48+
49+
async def main():
50+
tasks = [
51+
asyncio.create_task(c)
52+
for c in [a(0, "hello1"), a(0.1, "hello2"), a(0.2, "hello3"), a(0.3, "hello4")]
53+
]
54+
await asyncio.wait(tasks)
4555

4656

47-
loop = asyncio.get_event_loop()
48-
loop.run_until_complete(
49-
asyncio.wait(
50-
[a(0, "hello1"), a(0.75, "hello2"), a(1.5, "hello3"), a(2.25, "hello4")]
51-
)
52-
)
57+
asyncio.run(main(), debug=True)
5358

5459

5560
assert ls == [
@@ -72,41 +77,43 @@ async def a(s, m):
7277
]
7378

7479

75-
class TestAsyncWith(unittest.TestCase):
76-
def testAenterAttributeError1(self):
77-
class LacksAenter(object):
78-
async def __aexit__(self, *exc):
79-
pass
80+
if sys.version_info < (3, 11, 0):
8081

81-
async def foo():
82-
async with LacksAenter():
83-
pass
84-
85-
with self.assertRaisesRegex(AttributeError, '__aenter__'):
86-
foo().send(None)
82+
class TestAsyncWith(unittest.TestCase):
83+
def testAenterAttributeError1(self):
84+
class LacksAenter(object):
85+
async def __aexit__(self, *exc):
86+
pass
8787

88-
def testAenterAttributeError2(self):
89-
class LacksAenterAndAexit(object):
90-
pass
88+
async def foo():
89+
async with LacksAenter():
90+
pass
9191

92-
async def foo():
93-
async with LacksAenterAndAexit():
92+
with self.assertRaisesRegex(AttributeError, "__aenter__"):
93+
foo().send(None)
94+
95+
def testAenterAttributeError2(self):
96+
class LacksAenterAndAexit(object):
9497
pass
9598

96-
with self.assertRaisesRegex(AttributeError, '__aenter__'):
97-
foo().send(None)
99+
async def foo():
100+
async with LacksAenterAndAexit():
101+
pass
98102

99-
def testAexitAttributeError(self):
100-
class LacksAexit(object):
101-
async def __aenter__(self):
102-
pass
103+
with self.assertRaisesRegex(AttributeError, "__aenter__"):
104+
foo().send(None)
103105

104-
async def foo():
105-
async with LacksAexit():
106-
pass
107-
108-
with self.assertRaisesRegex(AttributeError, '__aexit__'):
109-
foo().send(None)
106+
def testAexitAttributeError(self):
107+
class LacksAexit(object):
108+
async def __aenter__(self):
109+
pass
110+
111+
async def foo():
112+
async with LacksAexit():
113+
pass
114+
115+
with self.assertRaisesRegex(AttributeError, "__aexit__"):
116+
foo().send(None)
110117

111118

112119
if __name__ == "__main__":

0 commit comments

Comments
 (0)