Skip to content

Commit 65a8b6c

Browse files
committed
docs(config[_atomic_write]) add doctests for atomic write and symlink behavior
why: _atomic_write had no doctest coverage. Inline examples show basic usage and the symlink-preservation guarantee introduced in this branch. what: - Add doctest for basic atomic write - Add doctest demonstrating symlink preservation
1 parent d37d513 commit 65a8b6c

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/vcspull/config.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,26 @@ def _atomic_write(target: pathlib.Path, content: str) -> None:
678678
Destination file path (may be a symlink)
679679
content : str
680680
Content to write
681+
682+
Examples
683+
--------
684+
>>> import pathlib, tempfile
685+
>>> with tempfile.TemporaryDirectory() as tmp:
686+
... p = pathlib.Path(tmp) / "test.txt"
687+
... _atomic_write(p, "hello")
688+
... p.read_text()
689+
'hello'
690+
691+
Symlinks are preserved — the real target is updated:
692+
693+
>>> with tempfile.TemporaryDirectory() as tmp:
694+
... real = pathlib.Path(tmp) / "real.txt"
695+
... _ = real.write_text("old", encoding="utf-8")
696+
... link = pathlib.Path(tmp) / "link.txt"
697+
... link.symlink_to(real)
698+
... _atomic_write(link, "new")
699+
... link.is_symlink()
700+
True
681701
"""
682702
# Resolve symlinks so the temp file lives next to the real
683703
# destination and the rename replaces the real file, not the symlink.

0 commit comments

Comments
 (0)