shortstats/tests/unitaires/test_themes.py
ploush 81ef12a9cd
Some checks failed
build / test (push) Failing after 2m48s
build / images (collector) (push) Has been skipped
build / images (web) (push) Has been skipped
upgrade 1.4.0
2026-11-29 20:43:50 +01:00

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("…")