Skip to content

Commit

Permalink
Fix CI not run on Windows (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet authored Feb 19, 2025
1 parent 29a84ae commit b61df30
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ jobs:
name: Unit Tests - Python ${{ matrix.python-version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.12', '3.13']
os:
- macos
- ubuntu
# - windows
- windows
steps:
- uses: actions/checkout@v4
with:
Expand Down
15 changes: 10 additions & 5 deletions blockbuster/blockbuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ def wrapper(*args: Any, **kwargs: Any) -> _T:
in_test_module = False
while frame:
frame_info = inspect.getframeinfo(frame)
frame_file_name = Path(frame_info.filename).as_posix()
if not in_test_module:
in_excluded_module = False
for excluded_module in excluded_modules:
if frame_file_name.startswith(excluded_module):
if frame_info.filename.startswith(excluded_module):
in_excluded_module = True
break
if not in_excluded_module:
for module in modules:
if frame_file_name.startswith(module):
if frame_info.filename.startswith(module):
in_test_module = True
break
frame_file_name = Path(frame_info.filename).as_posix()
for filename, functions in can_block_functions:
if (
frame_file_name.endswith(filename)
Expand Down Expand Up @@ -381,22 +381,27 @@ def _get_os_wrapped_functions(
def os_rw_exclude(fd: int, *_: Any, **__: Any) -> bool:
return hasattr(os, "get_blocking") and not os.get_blocking(fd)

os_rw_kwargs = (
{} if platform.system() == "Windows" else {"can_block_predicate": os_rw_exclude}
)

functions["os.read"] = BlockBusterFunction(
None,
"os.read",
can_block_predicate=os_rw_exclude,
can_block_functions=[
("asyncio/base_events.py", {"subprocess_shell"}),
],
scanned_modules=modules,
excluded_modules=excluded_modules,
**os_rw_kwargs,
)
functions["os.write"] = BlockBusterFunction(
None,
"os.write",
can_block_predicate=os_rw_exclude,
can_block_functions=None,
scanned_modules=modules,
excluded_modules=excluded_modules,
**os_rw_kwargs,
)

return functions
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "blockbuster"
version = "1.5.18"
version = "1.5.19"
description = "Utility to detect blocking calls in the async event loop"
readme = "README.md"
keywords = ["async", "block", "detect", "event loop", "asyncio"]
Expand Down
23 changes: 21 additions & 2 deletions tests/test_blockbuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import importlib
import io
import os
import platform
import re
import socket
import sqlite3
Expand Down Expand Up @@ -252,6 +253,9 @@ async def test_os_read() -> None:
os.read(fd, 1)


@pytest.mark.skipif(
platform.system() == "Windows", reason="O_NONBLOCK not supported on Windows"
)
async def test_os_read_non_blocking() -> None:
fd = os.open(os.devnull, os.O_NONBLOCK | os.O_RDONLY)
os.read(fd, 1)
Expand All @@ -263,6 +267,9 @@ async def test_os_write() -> None:
os.write(fd, b"foo")


@pytest.mark.skipif(
platform.system() == "Windows", reason="O_NONBLOCK not supported on Windows"
)
async def test_os_write_non_blocking() -> None:
fd = os.open(os.devnull, os.O_NONBLOCK | os.O_RDWR)
os.write(fd, b"foo")
Expand Down Expand Up @@ -296,7 +303,7 @@ async def test_os_rename() -> None:


async def test_os_renames() -> None:
with pytest.raises(BlockingError, match="Blocking call to os.stat"):
with pytest.raises(BlockingError, match="Blocking call to os.(stat|rename)"):
os.renames("/1", "/2")


Expand All @@ -316,7 +323,7 @@ async def test_os_mkdir() -> None:


async def test_os_makedirs() -> None:
with pytest.raises(BlockingError, match="Blocking call to os.stat"):
with pytest.raises(BlockingError, match="Blocking call to os.(stat|mkdir)"):
os.makedirs("/1")


Expand Down Expand Up @@ -360,16 +367,28 @@ async def test_os_access() -> None:
os.access("/1", os.F_OK)


@pytest.mark.skipif(
platform.system() == "Windows",
reason="os.path.exists not detected on Windows at the moment",
)
async def test_os_path_exists() -> None:
with pytest.raises(BlockingError, match="Blocking call to os.stat"):
os.path.exists("/1")


@pytest.mark.skipif(
platform.system() == "Windows",
reason="os.path.isfile not detected on Windows at the moment",
)
async def test_os_path_isfile() -> None:
with pytest.raises(BlockingError, match="Blocking call to os.stat"):
os.path.isfile("/1")


@pytest.mark.skipif(
platform.system() == "Windows",
reason="os.path.isdir not detected on Windows at the moment",
)
async def test_os_path_isdir() -> None:
with pytest.raises(BlockingError, match="Blocking call to os.stat"):
os.path.isdir("/1")
Expand Down
3 changes: 2 additions & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b61df30

Please sign in to comment.