Debian Codegraph @

tests/lib/tools/test_files.py

raw
1 from __future__ import annotations
2
3 from pathlib import Path
4
5 from anthropic.lib.tools._files import read_text_exact, write_text_exact
6
7
8 def test_read_text_exact_keeps_crlf_and_lone_cr(tmp_path: Path) -> None:
9 path = tmp_path / "f.txt"
10 path.write_bytes(b"a\r\nb\rc\n")
11 assert read_text_exact(path) == "a\r\nb\rc\n"
12 assert path.read_text(encoding="utf-8") == "a\nb\nc\n"
13
14
15 def test_write_text_exact_writes_verbatim(tmp_path: Path) -> None:
16 path = tmp_path / "f.txt"
17 write_text_exact(path, "a\r\nb\rc\né")
18 assert path.read_bytes() == b"a\r\nb\rc\n\xc3\xa9"