pospell/tests/test_pospell.py

68 lines
2.6 KiB
Python
Raw Normal View History

from pathlib import Path
import pytest
from pospell import clear, strip_rst, spell_check
2019-10-16 15:51:50 +00:00
def test_clear():
# We don't remove legitimally capitalized first words:
assert clear("Sport is great.") == "Sport is great."
assert clear("Sport is great.", True) == "Sport is great."
# Sometimes we can't guess it's a firstname:
assert clear("Julien Palard teste.") == "Julien Palard teste."
assert "Palard" not in clear("Julien Palard teste.", True)
# We remove capitalized words in the middle of a sentence
# they are typically names
assert clear("Great is Unicode.") == "Great is Unicode."
assert "Unicode" not in clear("Great is Unicode.", True)
# We remove capitalized words even prefixed with l' in french.
assert clear("Bah si, l'Unicode c'est bien.") == "Bah si, l'Unicode c'est bien."
assert "Unicode" not in clear("Bah si, l'Unicode c'est bien.", True)
# We remove single letters in quotes
assert "é" not in clear("La lettre « é » est seule.")
2019-05-23 18:45:04 +00:00
2019-09-30 11:37:48 +00:00
# We remove soft hyphens
assert clear("some\xadthing") == "something"
2019-09-30 11:37:48 +00:00
# When we removed a dashed name, remove it all
assert clear("Marc-André Lemburg a fait").strip() == "Marc-André Lemburg a fait"
assert "Marc-André" in clear("Marc-André Lemburg a fait", True)
assert "Lemburg" not in clear("Marc-André Lemburg a fait", True)
# Even in the middle of a sentence
assert clear("Hier, Marc-André Lemburg a fait") == "Hier, Marc-André Lemburg a fait"
assert "Marc-André" not in clear("Hier, Marc-André Lemburg a fait", True)
assert "André" not in clear("Hier, Marc-André Lemburg a fait", True)
assert "Marc" not in clear("Hier, Marc-André Lemburg a fait", True)
assert "Lemburg" not in clear("Hier, Marc-André Lemburg a fait", True)
2019-08-20 14:38:03 +00:00
2019-11-16 13:47:22 +00:00
# We remove variables
assert "days_since" not in clear("Starting {days_since} days ago")
2019-11-16 13:47:22 +00:00
# Double space should change nothing
assert clear("Test. Aujourd'hui, j'ai faim.") == clear(
"Test. Aujourd'hui, j'ai faim."
)
2019-10-16 15:03:15 +00:00
assert ":pep:`305`" not in clear(strip_rst(":pep:`305` - Interface des fichiers"))
2019-10-16 15:51:50 +00:00
FIXTURE_DIR = Path(__file__).resolve().parent
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "expected_to_fail").glob("*.po"))
def test_expected_to_fail(po_file, capsys):
assert spell_check([po_file]) > 0
assert not capsys.readouterr().err
@pytest.mark.parametrize("po_file", (FIXTURE_DIR / "expected_to_success").glob("*.po"))
def test_expected_to_success(po_file, capsys):
assert spell_check([po_file]) == 0
assert not capsys.readouterr().err