@@ -9,27 +9,31 @@ async def sample_coro():
9
9
return 'done'
10
10
11
11
12
+ async def await_helper (awaitable_obj ):
13
+ """Helper to await objects in tasks."""
14
+ return await awaitable_obj
15
+
16
+
12
17
@pytest .mark .anyio
13
18
async def test_concurrent_awaitable ():
19
+ """Test that ReAwaitable works with concurrent awaits."""
14
20
test_target = ReAwaitable (sample_coro ())
15
21
16
- async def await_reawaitable ():
17
- return await test_target
18
22
async with anyio .create_task_group () as tg :
19
- task1 = tg .start_soon (await_reawaitable )
20
- task2 = tg .start_soon (await_reawaitable )
23
+ tg .start_soon (await_helper , test_target )
24
+ tg .start_soon (await_helper , test_target )
21
25
22
26
23
- @ pytest . mark . anyio
24
- async def test_reawaitable_decorator ():
25
- """Test the reawaitable decorator with concurrent awaits."" "
27
+ async def _test_coro (): # noqa: WPS430
28
+ await anyio . sleep ( 0.1 )
29
+ return "decorated "
26
30
27
- @reawaitable
28
- async def decorated_coro ():
29
- await anyio .sleep (0.1 )
30
- return "decorated"
31
31
32
- instance = decorated_coro ()
32
+ @pytest .mark .anyio # noqa: WPS210
33
+ async def test_reawaitable_decorator ():
34
+ """Test the reawaitable decorator with concurrent awaits."""
35
+ decorated = reawaitable (_test_coro )
36
+ instance = decorated ()
33
37
34
38
# Test multiple awaits
35
39
result1 = await instance
@@ -39,26 +43,22 @@ async def decorated_coro():
39
43
assert result1 == result2
40
44
41
45
# Test concurrent awaits
42
- async def await_decorated ():
43
- return await instance
44
-
45
46
async with anyio .create_task_group () as tg :
46
- task1 = tg .start_soon (await_decorated )
47
- task2 = tg .start_soon (await_decorated )
47
+ tg .start_soon (await_helper , instance )
48
+ tg .start_soon (await_helper , instance )
48
49
49
50
50
51
@pytest .mark .anyio
51
52
async def test_reawaitable_repr ():
52
53
"""Test the __repr__ method of ReAwaitable."""
53
-
54
- async def test_func ():
54
+
55
+ async def test_func (): # noqa: WPS430
55
56
return 1
56
-
57
+
57
58
coro = test_func ()
58
- reawaitable = ReAwaitable (coro )
59
-
59
+ target = ReAwaitable (coro )
60
+
60
61
# Test the representation
61
- assert repr (reawaitable ) == repr (coro )
62
-
62
+ assert repr (target ) == repr (coro )
63
63
# Ensure the coroutine is properly awaited
64
- await reawaitable
64
+ await target
0 commit comments