Skip to content

Commit 4bb66e0

Browse files
fix: platform-specific coverage config
1 parent 7214725 commit 4bb66e0

File tree

5 files changed

+11
-26
lines changed

5 files changed

+11
-26
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ exclude_lines = [
161161
"uvicorn/supervisors/multiprocess.py",
162162
"tests/supervisors/test_multiprocess.py",
163163
]
164-
"sys_platform != 'win32'" = ["uvicorn/loops/asyncio.py"]
164+
"sys_platform != 'win32'" = [
165+
"uvicorn/loops/winloop.py",
166+
]
165167

166168
[tool.coverage.coverage_conditional_plugin.rules]
167169
py-win32 = "sys_platform == 'win32'"

tests/test_auto_detection.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@
1111
from uvicorn.protocols.websockets.auto import AutoWebSocketsProtocol
1212
from uvicorn.server import ServerState
1313

14-
# Determine expected loop implementation based on platform
1514
try:
16-
if sys.platform == "win32":
17-
# On Windows, check for winloop first, then asyncio
15+
if sys.platform == "win32": # pragma: py-not-win32
1816
importlib.import_module("winloop")
1917
expected_loop = "winloop"
20-
else:
21-
# On Unix, check for uvloop first, then asyncio
18+
else: # pragma: py-win32
2219
importlib.import_module("uvloop")
23-
expected_loop = "uvloop" # pragma: py-win32
24-
except ImportError: # pragma: py-not-win32
20+
expected_loop = "uvloop"
21+
except ImportError: # pragma: no cover
2522
expected_loop = "asyncio"
2623

2724
try:

tests/test_config.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -593,17 +593,3 @@ def test_setup_event_loop_is_removed(caplog: pytest.LogCaptureFixture) -> None:
593593
AttributeError, match="The `setup_event_loop` method was replaced by `get_loop_factory` in uvicorn 0.36.0."
594594
):
595595
config.setup_event_loop()
596-
597-
598-
@pytest.mark.skipif(sys.platform != "win32", reason="winloop is for Windows only")
599-
def test_winloop_loop_factory() -> None:
600-
"""Test that winloop can be explicitly configured on Windows."""
601-
pytest.importorskip("winloop")
602-
config = Config(app=asgi_app, loop="winloop")
603-
config.load()
604-
loop_factory = config.get_loop_factory()
605-
assert loop_factory is not None
606-
event_loop = loop_factory()
607-
with closing(event_loop):
608-
assert event_loop is not None
609-
assert type(event_loop).__module__.startswith("winloop")

uvicorn/loops/asyncio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77

88
def asyncio_loop_factory(use_subprocess: bool = False) -> Callable[[], asyncio.AbstractEventLoop]:
9-
if sys.platform == "win32" and not use_subprocess:
9+
if sys.platform == "win32" and not use_subprocess: # pragma: py-not-win32
1010
return asyncio.ProactorEventLoop
11-
return asyncio.SelectorEventLoop
11+
return asyncio.SelectorEventLoop # pragma: py-win32

uvicorn/loops/auto.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
def auto_loop_factory(use_subprocess: bool = False) -> Callable[[], asyncio.AbstractEventLoop]:
99
try:
10-
if sys.platform == "win32":
10+
if sys.platform == "win32": # pragma: py-not-win32
1111
from uvicorn.loops.winloop import winloop_loop_factory as loop_factory
12-
else:
12+
else: # pragma: py-win32
1313
from uvicorn.loops.uvloop import uvloop_loop_factory as loop_factory
1414
except ImportError: # pragma: no cover
1515
from uvicorn.loops.asyncio import asyncio_loop_factory as loop_factory

0 commit comments

Comments
 (0)