62 """Test that dry-run mode doesn't modify files."""
63 test_file = temp_project_root /
"test.py"
68 +
"\n".join([
"# padding"] * 20)
70 test_file.write_text(original_content, encoding=
"utf-8")
72 run_formatter(temp_project_root, [
"--dry-run"])
74 assert test_file.read_text(encoding=
"utf-8") == original_content
78 """Test that fix mode applies changes and archives originals."""
79 test_file = temp_project_root /
"test.py"
84 +
"\n".join([
"# padding"] * 20)
86 test_file.write_text(original_content, encoding=
"utf-8")
88 run_formatter(temp_project_root, [
"--fix"])
91 new_content = test_file.read_text(encoding=
"utf-8")
92 assert new_content != original_content
93 assert new_content.startswith(
"#!/usr/bin/env python3")
96 archive_dir = test_file.parent /
".formatter_archive"
97 assert archive_dir.exists()
98 backups = list(archive_dir.glob(
"test.py.*"))
99 assert len(backups) == 1
103 """Test that JSON output is valid and has correct schema."""
104 test_file = temp_project_root /
"test.py"
105 test_file.write_text(
109 +
"\n".join([
"# padding"] * 20),
113 run_formatter(temp_project_root, [
"--dry-run",
"--json"])
115 captured = capsys.readouterr()
116 output = captured.out
119 data = json.loads(output)
122 assert "project" in data
123 assert "oct_version" in data
124 assert "timestamp" in data
125 assert "summary" in data
126 assert "files" in data
127 assert "dry_run" in data
130 assert "total_files" in data[
"summary"]
131 assert "total_changed" in data[
"summary"]
132 assert "fixes" in data[
"summary"]
136 """Test that verbose mode shows per-file details."""
137 test_file = temp_project_root /
"test.py"
138 test_file.write_text(
142 +
"\n".join([
"# padding"] * 20),
146 run_formatter(temp_project_root, [
"--dry-run",
"--verbose"])
148 captured = capsys.readouterr()
149 output = captured.out
152 assert "Detailed results:" in output
153 assert "test.py" in output
157 """Test that excluded directories are not processed."""
159 excluded_dir = temp_project_root /
".git"
161 excluded_file = excluded_dir /
"test.py"
162 original_content =
"# No header\n" +
"\n".join([
"# padding"] * 20)
163 excluded_file.write_text(original_content, encoding=
"utf-8")
165 run_formatter(temp_project_root, [
"--fix"])
168 assert excluded_file.read_text(encoding=
"utf-8") == original_content