Skip to content

Commit d2eeeee

Browse files
committed
test: add test for change list in write mode
1 parent 25ad520 commit d2eeeee

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

codespell_lib/tests/test_basic.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,29 @@ def test_basic(
168168
(tmp_path / "empty").mkdir()
169169
assert cs.main(tmp_path) == 0
170170

171+
def test_write_changes_lists_changes(
172+
tmp_path: Path,
173+
capsys: pytest.CaptureFixture[str],
174+
) -> None:
175+
"""Test that -w flag shows list of changes made to file."""
176+
177+
fname = tmp_path / "misspelled.txt"
178+
fname.write_text("This is abandonned\nAnd this is occured\nAlso teh typo\n")
179+
180+
result = cs.main("-w", fname, std=True)
181+
assert isinstance(result, tuple)
182+
code, _, stderr = result
183+
assert code == 0
184+
185+
assert "FIXED:" in stderr
186+
187+
# Check that changes are listed with format: filename:line: wrong ==> right
188+
assert "misspelled.txt:1: abandonned ==> abandoned" in stderr
189+
assert "misspelled.txt:2: occured ==> occurred" in stderr
190+
assert "misspelled.txt:3: teh ==> the" in stderr
191+
192+
corrected = fname.read_text()
193+
assert corrected == "This is abandoned\nAnd this is occurred\nAlso the typo\n"
171194

172195
def test_default_word_parsing(
173196
tmp_path: Path,

0 commit comments

Comments
 (0)