-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_diff_tools.py
More file actions
65 lines (49 loc) · 1.75 KB
/
test_diff_tools.py
File metadata and controls
65 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Generated by Claude Code
import csv
import subprocess
import platform
from pathlib import Path
from textwrap import dedent
_SCRIPT_DIR = Path(__file__).parent
CURRENT_OS = {
"Darwin": "Mac",
"Linux": "Linux",
"Windows": "Windows",
}[platform.system()]
def _load_tool(name: str) -> dict[str, str]:
with (_SCRIPT_DIR / "diff_reporters.csv").open(newline="") as f:
for row in csv.DictReader(f):
if row["name"] == name and row["os"] == CURRENT_OS:
return row
assert False, f"Tool {name} not found for OS {CURRENT_OS}"
def _compose_command(tool: dict[str, str], path1: Path, path2: Path) -> list[str]:
arguments = tool["arguments"]
if "%s" in arguments:
replaced = arguments.replace("%s", str(path1), 1).replace("%s", str(path2), 1)
return [tool["path"], *replaced.split()]
else:
return [tool["path"], *arguments.split(), str(path1), str(path2)]
def test_identical_files(tmp_path: Path) -> None:
reporter = _load_tool("DIFF_COMMAND_LINE")
file1 = tmp_path / "a.txt"
file1.write_text(dedent("""\
XXX
"""))
file2 = tmp_path / "b.txt"
file2.write_text(dedent("""\
XXX
"""))
result = subprocess.run(_compose_command(reporter, file1, file2), text=True, capture_output=True)
assert result.returncode == 0
def test_different_files(tmp_path: Path) -> None:
reporter = _load_tool("DIFF_COMMAND_LINE")
file1 = tmp_path / "a.txt"
file1.write_text(dedent("""\
XXX
"""))
file2 = tmp_path / "b.txt"
file2.write_text(dedent("""\
XXXXXXXXXXXXXX
"""))
result = subprocess.run(_compose_command(reporter, file1, file2), text=True, capture_output=True)
assert result.returncode == 1