Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add coverage-conditional-plugin plugin #1159

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ types-pyyaml
trustme
cryptography
coverage
coverage-conditional-plugin
httpx>=0.18.2
pytest-asyncio==0.14.*
async_generator; python_version < '3.7'
Expand Down
2 changes: 1 addition & 1 deletion scripts/coverage
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export SOURCE_FILES="uvicorn tests"

set -x

${PREFIX}coverage report --show-missing --skip-covered --fail-under=95
${PREFIX}coverage report --show-missing --skip-covered --fail-under=97
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ filterwarnings=
[coverage:run]
omit = venv/*
include = uvicorn/*, tests/*
plugins =
coverage_conditional_plugin

[coverage:coverage_conditional_plugin]
rules =
"sys_platform == 'win32'": py-win32
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_cli_call_multiprocess_run() -> None:


@pytest.mark.skipif(sys.platform == "win32", reason="require unix-like system")
def test_cli_uds(tmp_path: Path) -> None:
def test_cli_uds(tmp_path: Path) -> None: # pragma: py-win32
runner = CliRunner()
uds_file = tmp_path / "uvicorn.sock"
uds_file.touch(exist_ok=True)
Expand Down
6 changes: 4 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,9 @@ def test_ws_max_size() -> None:
ids=["--reload=True --workers=1", "--reload=False --workers=2"],
)
@pytest.mark.skipif(sys.platform == "win32", reason="require unix-like system")
def test_bind_unix_socket_works_with_reload_or_workers(tmp_path, reload, workers):
def test_bind_unix_socket_works_with_reload_or_workers(
tmp_path, reload, workers
): # pragma: py-win32
uds_file = tmp_path / "uvicorn.sock"
config = Config(
app=asgi_app, uds=uds_file.as_posix(), reload=reload, workers=workers
Expand All @@ -535,7 +537,7 @@ def test_bind_unix_socket_works_with_reload_or_workers(tmp_path, reload, workers
ids=["--reload=True --workers=1", "--reload=False --workers=2"],
)
@pytest.mark.skipif(sys.platform == "win32", reason="require unix-like system")
def test_bind_fd_works_with_reload_or_workers(reload, workers):
def test_bind_fd_works_with_reload_or_workers(reload, workers): # pragma: py-win32
fdsock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
fd = fdsock.fileno()
config = Config(app=asgi_app, fd=fd, reload=reload, workers=workers)
Expand Down
6 changes: 3 additions & 3 deletions uvicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def setup_event_loop(self) -> None:

def bind_socket(self) -> socket.socket:
logger_args: List[Union[str, int]]
if self.uds:
if self.uds: # pragma: py-win32
path = self.uds
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
Expand All @@ -516,7 +516,7 @@ def bind_socket(self) -> socket.socket:
+ " (Press CTRL+C to quit)"
)
logger_args = [self.uds]
elif self.fd:
elif self.fd: # pragma: py-win32
sock = socket.fromfd(self.fd, socket.AF_UNIX, socket.SOCK_STREAM)
message = "Uvicorn running on socket %s (Press CTRL+C to quit)"
fd_name_format = "%s"
Expand All @@ -530,7 +530,7 @@ def bind_socket(self) -> socket.socket:
family = socket.AF_INET
addr_format = "%s://%s:%d"

if self.host and ":" in self.host:
if self.host and ":" in self.host: # pragma: py-win32
# It's an IPv6 address.
family = socket.AF_INET6
addr_format = "%s://[%s]:%d"
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def run(app: typing.Union[ASGIApplication, str], **kwargs: typing.Any) -> None:
else:
server.run()
if config.uds:
os.remove(config.uds)
os.remove(config.uds) # pragma: py-win32


if __name__ == "__main__":
Expand Down