forked from AFPy/pospell
Fix compounding error causing false negatives, hope it won't raise false positives.
This commit is contained in:
parent
863b7a4bd6
commit
e7bc8f86ee
16
pospell.py
16
pospell.py
|
@ -246,7 +246,11 @@ def parse_args():
|
|||
|
||||
|
||||
def spell_check(
|
||||
po_files, personal_dict, language, drop_capitalized=False, debug_only=False
|
||||
po_files,
|
||||
personal_dict=None,
|
||||
language="en_EN",
|
||||
drop_capitalized=False,
|
||||
debug_only=False,
|
||||
):
|
||||
"""Check for spelling mistakes in the files po_files (po format,
|
||||
containing restructuredtext), for the given language.
|
||||
|
@ -273,12 +277,10 @@ def spell_check(
|
|||
if not output.stdout:
|
||||
continue # No errors :)
|
||||
line_of_words = defaultdict(set)
|
||||
for line, text in enumerate(text_for_hunspell.split("\n"), start=1):
|
||||
for word in text.split():
|
||||
line_of_words[word].add(line)
|
||||
for misspelled_word in set(output.stdout.split("\n")):
|
||||
for line_number in line_of_words[misspelled_word]:
|
||||
errors.append((po_file, line_number, misspelled_word))
|
||||
for misspelled_word in {word for word in output.stdout.split("\n") if word}:
|
||||
for line_number, line in enumerate(text_for_hunspell.split("\n"), start=1):
|
||||
if misspelled_word in line:
|
||||
errors.append((po_file, line_number, misspelled_word))
|
||||
errors.sort()
|
||||
for error in errors:
|
||||
print(":".join(str(token) for token in error))
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
from pospell import clear, strip_rst
|
||||
from types import SimpleNamespace
|
||||
from pathlib import Path
|
||||
|
||||
from pospell import clear, strip_rst, spell_check
|
||||
|
||||
|
||||
def test_clear():
|
||||
|
@ -70,3 +73,66 @@ def test_clear_accronyms():
|
|||
assert "HTTP" not in clear("Yes HTTP is great.", drop_capitalized)
|
||||
|
||||
assert "PEPs" not in clear("Ho. PEPs good.", drop_capitalized)
|
||||
|
||||
|
||||
def test_with_an_error(tmp_path, capsys, monkeypatch):
|
||||
import subprocess
|
||||
|
||||
tmp_path = Path(tmp_path)
|
||||
monkeypatch.setattr(
|
||||
subprocess,
|
||||
"run",
|
||||
lambda *args, **kwargs: SimpleNamespace(stdout="Pyhton\n"),
|
||||
)
|
||||
(tmp_path / "test.po").write_text(
|
||||
"""
|
||||
msgid "Python FTW!"
|
||||
msgstr "Gloire à Pyhton !"
|
||||
"""
|
||||
)
|
||||
assert spell_check([tmp_path / "test.po"]) > 0
|
||||
captured = capsys.readouterr()
|
||||
assert "Pyhton" in captured.out
|
||||
assert not captured.err
|
||||
|
||||
|
||||
def test_with_no_error(tmp_path, capsys, monkeypatch):
|
||||
import subprocess
|
||||
|
||||
tmp_path = Path(tmp_path)
|
||||
monkeypatch.setattr(
|
||||
subprocess,
|
||||
"run",
|
||||
lambda *args, **kwargs: SimpleNamespace(stdout=""),
|
||||
)
|
||||
(tmp_path / "test.po").write_text(
|
||||
"""
|
||||
msgid "Python FTW!"
|
||||
msgstr "Gloire à Python !"
|
||||
"""
|
||||
)
|
||||
assert spell_check([tmp_path / "test.po"]) == 0
|
||||
captured = capsys.readouterr()
|
||||
assert not captured.out
|
||||
assert not captured.err
|
||||
|
||||
|
||||
def test_issue_19(tmp_path, capsys, monkeypatch):
|
||||
import subprocess
|
||||
|
||||
tmp_path = Path(tmp_path)
|
||||
monkeypatch.setattr(
|
||||
subprocess,
|
||||
"run",
|
||||
lambda *args, **kwargs: SimpleNamespace(stdout="pubb\nsubb\n"),
|
||||
)
|
||||
(tmp_path / "test.po").write_text(
|
||||
"""
|
||||
msgid "pubb/subb yo"
|
||||
msgstr "pubb/subb"
|
||||
"""
|
||||
)
|
||||
assert spell_check([tmp_path / "test.po"]) > 0
|
||||
captured = capsys.readouterr()
|
||||
assert "pubb" in captured.out
|
||||
assert not captured.err
|
||||
|
|
Loading…
Reference in New Issue
Block a user