23 lines
1,023 B
Python
23 lines
1,023 B
Python
"""Thèmes de commentaires : nettoyage des expressions, extraits."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from shortstats.web.data.repo import MARK_CLOSE, MARK_OPEN, clean_patterns, excerpt
|
|
|
|
|
|
def test_clean_patterns():
|
|
assert clean_patterns(["a", "", " ", "a", " b "]) == ["a", " b "] # les espaces comptent
|
|
assert clean_patterns("x") == ["x"]
|
|
for bad, msg in [([], "Au moins"), (["", " "], "Au moins"), (["x" * 301], "trop longue"),
|
|
([str(i) for i in range(21)], "20 expressions"), (["a\x00"], "nul"), ([3], "invalide")]:
|
|
with pytest.raises(ValueError, match=msg):
|
|
clean_patterns(bad)
|
|
|
|
|
|
def test_excerpt():
|
|
text = "x" * 100 + "début " + MARK_OPEN + "Apple Pie" + MARK_CLOSE + " fin\n\nde texte" + "y" * 100
|
|
out = excerpt("v", "Titre", text)
|
|
assert out["match"] == "Apple Pie" and out["before"].startswith("…") and out["before"].endswith("début ")
|
|
assert out["after"].startswith(" fin de texte") and out["after"].endswith("…")
|