You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_write_text_atomic_preserves_existing_mode asserts POSIX mode bits that Windows cannot represent #2622
Labels: bug, tests, windows, good first issue Version: 0.9.38 (commit 10ad921)
Summary
The test sets 0o644 on a file and asserts the atomic write preserves it. Windows does not
implement POSIX permission bits — os.chmod only toggles the read-only attribute, and os.stat().st_mode reports 0o666 for any writable file. The assertion can never hold.
def test_write_text_atomic_preserves_existing_mode(tmp_path):
# An atomic replace must not tighten a 0644 file to mkstemp's 0600 default.
p = tmp_path / "graph.json"
p.write_text("{}", encoding="utf-8")
os.chmod(p, 0o644)
write_text_atomic(p, '{"x": 1}')
> assert (os.stat(p).st_mode & 0o777) == 0o644
E AssertionError: assert (33206 & 511) == 420
33206 is 0o100666, so st_mode & 0o777 is 0o666, not 0o644. The os.chmod(p, 0o644)
on line 4 did not do what the test assumes — on Windows it is a no-op for anything other
than the read-only bit.
Expected behavior
Skipped on Windows. The property under test — "an atomic replace must not tighten a 0644 file
to mkstemp's 0600 default" — is a POSIX property with no Windows equivalent.
Suggested fix
@pytest.mark.skipif(os.name=="nt",reason="Windows has no POSIX mode bits; chmod only toggles the read-only attribute",)deftest_write_text_atomic_preserves_existing_mode(tmp_path):
...
If Windows coverage of write_text_atomic is wanted, the meaningful analogue is the
read-only attribute surviving a replace:
Fixed in v0.9.42 (graphifyy==0.9.42 on PyPI). The POSIX-mode assertion is skipped on Windows with a Windows analogue added, and a failed atomic write no longer leaks a read-only temp. Thanks @rajarshidattapy (PR #2623).
Activity
fix(paths): clear read-only bit before unlinking the atomic-write tem…
safishamsi commentedon Aug 13, 2026
Fixed in v0.9.42 (
graphifyy==0.9.42on PyPI). The POSIX-mode assertion is skipped on Windows with a Windows analogue added, and a failed atomic write no longer leaks a read-only temp. Thanks @rajarshidattapy (PR #2623).