1
+ from __future__ import annotations
2
+
1
3
import sys
2
- from typing import Any , Tuple
4
+ from typing import TYPE_CHECKING
3
5
4
6
import pytest
5
7
6
8
from .. import _core
7
9
from ..testing import check_one_way_stream , wait_all_tasks_blocked
8
10
11
+ # Mark all the tests in this file as being windows-only
12
+ pytestmark = pytest .mark .skipif (sys .platform != "win32" , reason = "windows only" )
13
+
14
+ assert ( # Skip type checking when not on Windows
15
+ sys .platform == "win32" or not TYPE_CHECKING
16
+ )
17
+
9
18
if sys .platform == "win32" :
10
19
from asyncio .windows_utils import pipe
11
20
12
21
from .._core ._windows_cffi import _handle , kernel32
13
22
from .._windows_pipes import PipeReceiveStream , PipeSendStream
14
- else :
15
- pytestmark = pytest .mark .skip (reason = "windows only" )
16
- pipe : Any = None
17
- PipeSendStream : Any = None
18
- PipeReceiveStream : Any = None
19
23
20
24
21
- async def make_pipe () -> Tuple [PipeSendStream , PipeReceiveStream ]:
25
+ async def make_pipe () -> tuple [PipeSendStream , PipeReceiveStream ]:
22
26
"""Makes a new pair of pipes."""
23
27
(r , w ) = pipe ()
24
28
return PipeSendStream (w ), PipeReceiveStream (r )
25
29
26
30
27
- async def test_pipe_typecheck ():
31
+ async def test_pipe_typecheck () -> None :
28
32
with pytest .raises (TypeError ):
29
- PipeSendStream (1.0 )
33
+ PipeSendStream (1.0 ) # type: ignore[arg-type]
30
34
with pytest .raises (TypeError ):
31
- PipeReceiveStream (None )
35
+ PipeReceiveStream (None ) # type: ignore[arg-type]
32
36
33
37
34
- async def test_pipe_error_on_close ():
38
+ async def test_pipe_error_on_close () -> None :
35
39
# Make sure we correctly handle a failure from kernel32.CloseHandle
36
40
r , w = pipe ()
37
41
@@ -47,18 +51,18 @@ async def test_pipe_error_on_close():
47
51
await receive_stream .aclose ()
48
52
49
53
50
- async def test_pipes_combined ():
54
+ async def test_pipes_combined () -> None :
51
55
write , read = await make_pipe ()
52
56
count = 2 ** 20
53
57
replicas = 3
54
58
55
- async def sender ():
59
+ async def sender () -> None :
56
60
async with write :
57
61
big = bytearray (count )
58
62
for _ in range (replicas ):
59
63
await write .send_all (big )
60
64
61
- async def reader ():
65
+ async def reader () -> None :
62
66
async with read :
63
67
await wait_all_tasks_blocked ()
64
68
total_received = 0
@@ -76,7 +80,7 @@ async def reader():
76
80
n .start_soon (reader )
77
81
78
82
79
- async def test_async_with ():
83
+ async def test_async_with () -> None :
80
84
w , r = await make_pipe ()
81
85
async with w , r :
82
86
pass
@@ -87,11 +91,11 @@ async def test_async_with():
87
91
await r .receive_some (10 )
88
92
89
93
90
- async def test_close_during_write ():
94
+ async def test_close_during_write () -> None :
91
95
w , r = await make_pipe ()
92
96
async with _core .open_nursery () as nursery :
93
97
94
- async def write_forever ():
98
+ async def write_forever () -> None :
95
99
with pytest .raises (_core .ClosedResourceError ) as excinfo :
96
100
while True :
97
101
await w .send_all (b"x" * 4096 )
@@ -102,7 +106,7 @@ async def write_forever():
102
106
await w .aclose ()
103
107
104
108
105
- async def test_pipe_fully ():
109
+ async def test_pipe_fully () -> None :
106
110
# passing make_clogged_pipe tests wait_send_all_might_not_block, and we
107
111
# can't implement that on Windows
108
112
await check_one_way_stream (make_pipe , None )
0 commit comments