Skip to content

Commit a2720ff

Browse files
authored
Hotfix statvfs (#172)
* Hotfix statvfs * Try testing on Windows * Tweak * Skip statvfs test on Windows * Lint * Skip sendfile on Windows * Tweak tests * Skip test on Windows * Skip some more Windows tests * Tweak more tests * Track coverage on Linux only * Tweak quotes
1 parent 6c083c9 commit a2720ff

6 files changed

Lines changed: 24 additions & 12 deletions

File tree

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ on:
1111
jobs:
1212
tests:
1313
name: "Python ${{ matrix.python-version }}"
14-
runs-on: "ubuntu-latest"
15-
14+
runs-on: ${{ matrix.os }}
1615
strategy:
1716
matrix:
17+
os: [ubuntu-latest, windows-latest]
1818
python-version:
1919
["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy-3.9"]
2020

@@ -28,7 +28,6 @@ jobs:
2828

2929
- name: "Install dependencies"
3030
run: |
31-
set -xe
3231
python -VV
3332
python -m site
3433
python -m pip install --upgrade pip wheel pdm
@@ -43,6 +42,7 @@ jobs:
4342
name: "coverage-data"
4443
path: ".coverage.*"
4544
if-no-files-found: "ignore"
45+
if: runner.os == 'Linux'
4646

4747
coverage:
4848
name: "Combine & check coverage."

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ async def test_stuff():
165165

166166
### History
167167

168+
#### 23.2.1 (2023-08-09)
169+
170+
- Import `os.statvfs` conditionally to fix importing on non-UNIX systems.
171+
[#171](https://github.com/Tinche/aiofiles/issues/171) [#172](https://github.com/Tinche/aiofiles/pull/172)
172+
168173
#### 23.2.0 (2023-08-09)
169174

170175
- aiofiles is now tested on Python 3.12 too.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "aiofiles"
3-
version = "23.3.0dev0"
3+
version = "23.2.1dev0"
44
description = "File support for asyncio."
55
authors = [
66
{name = "Tin Tvrtkovic", email = "tinchester@gmail.com"},

src/aiofiles/os.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030

3131
stat = wrap(os.stat)
32-
statvfs = wrap(os.statvfs)
3332
rename = wrap(os.rename)
3433
renames = wrap(os.renames)
3534
replace = wrap(os.replace)
@@ -48,3 +47,5 @@
4847

4948
if hasattr(os, "sendfile"):
5049
sendfile = wrap(os.sendfile)
50+
if hasattr(os, "statvfs"):
51+
statvfs = wrap(os.statvfs)

tests/test_os.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ async def test_stat():
2121
assert stat_res.st_size == 10
2222

2323

24+
@pytest.mark.skipif(platform.system() == "Windows", reason="No statvfs on Windows")
2425
@pytest.mark.asyncio
2526
async def test_statvfs():
2627
"""Test the statvfs call."""
@@ -118,7 +119,8 @@ async def test_replace():
118119
reason="sendfile() syscall doesn't allow file->file",
119120
)
120121
@pytest.mark.skipif(
121-
platform.system() == "Darwin", reason="sendfile() doesn't work on mac"
122+
platform.system() in ("Darwin", "Windows"),
123+
reason="sendfile() doesn't work on mac and Win",
122124
)
123125
@pytest.mark.asyncio
124126
async def test_sendfile_file(tmpdir):
@@ -148,6 +150,9 @@ async def test_sendfile_file(tmpdir):
148150
assert size == actual_size
149151

150152

153+
@pytest.mark.skipif(
154+
platform.system() in ("Windows"), reason="sendfile() doesn't work on Win"
155+
)
151156
@pytest.mark.asyncio
152157
async def test_sendfile_socket(unused_tcp_port):
153158
"""Test the sendfile functionality, file-to-socket."""
@@ -307,6 +312,9 @@ async def test_symlink():
307312
assert exists(src_filename) and exists(dst_filename) is False
308313

309314

315+
@pytest.mark.skipif(
316+
platform.system() == "Windows", reason="Doesn't work on Win properly"
317+
)
310318
@pytest.mark.asyncio
311319
async def test_readlink():
312320
"""Test the readlink call."""
@@ -450,6 +458,7 @@ async def test_scandir_non_existing_dir():
450458
await aiofiles.os.scandir(some_dir)
451459

452460

461+
@pytest.mark.skipif(platform.system() == "Windows", reason="Doesn't work on Win")
453462
@pytest.mark.asyncio
454463
async def test_access():
455464
temp_file = Path(__file__).parent.joinpath("resources", "os_access_temp.txt")

tests/test_tempfile.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import io
22
import os
3+
import platform
34
import sys
45

56
import pytest
@@ -120,14 +121,10 @@ async def test_spooled_temporary_file(mode):
120121
assert await f.read() == data + data
121122

122123

123-
@pytest.mark.asyncio
124124
@pytest.mark.skipif(
125-
sys.version_info < (3, 7),
126-
reason=(
127-
"text-mode SpooledTemporaryFile is implemented with StringIO in py3.6"
128-
"it doesn't support `newlines`"
129-
),
125+
platform.system() == "Windows", reason="Doesn't work on Win properly"
130126
)
127+
@pytest.mark.asyncio
131128
@pytest.mark.parametrize(
132129
"test_string, newlines", [("LF\n", "\n"), ("CRLF\r\n", "\r\n")]
133130
)

0 commit comments

Comments
 (0)