post_digest: заголовок = самая информативная фраза, чистка CAPS/гомоглифов/markdown, кликабельный сервис, тесты формата
This commit is contained in:
83
tests/test_post_digest.py
Normal file
83
tests/test_post_digest.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Формат дайджеста: чистка заголовков, объёмов, условий и группировка."""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tools"))
|
||||
|
||||
import post_digest as d # noqa: E402
|
||||
|
||||
|
||||
def test_homoglyph_fix():
|
||||
assert d.dehomoglyph("Cовет") == "Совет"
|
||||
assert d.dehomoglyph("GitHub") == "GitHub"
|
||||
|
||||
|
||||
def test_shout_to_sentence():
|
||||
out = d.smart_case("DEEPSEEK ПРОДОЛЖАЕТ РАЗДАВАТЬ ТОКЕНЫ")
|
||||
assert out.startswith("Deepseek")
|
||||
assert not any(w.isupper() and len(w) > 4 for w in out.split())
|
||||
|
||||
|
||||
def test_abbr_kept():
|
||||
out = d.smart_case("FREE ДОСТУП К ТОПОВЫМ LLM ЧЕРЕЗ GITHUB-OAUTH")
|
||||
assert "LLM" in out
|
||||
|
||||
|
||||
def test_headline_drops_lead_and_caps():
|
||||
out = d.headline("Cовет: не обязательно тратить большие деньги на инструменты ИИ")
|
||||
assert not out.lower().startswith("cовет")
|
||||
assert len(out) <= 80
|
||||
|
||||
|
||||
def test_headline_no_dangling_preposition():
|
||||
out = d.headline("RU 200 000 000 бесплатных токенов и тариф PRO на", n=40)
|
||||
assert not out.rstrip("…").endswith(" на")
|
||||
|
||||
|
||||
def test_gain_prefers_volume_over_price():
|
||||
assert d.gain("подписка $10, дают 5 млн токенов") == "5 млн токенов"
|
||||
|
||||
|
||||
def test_gain_skips_small_money():
|
||||
assert d.gain("подписка за $10 на неделю") == ""
|
||||
|
||||
|
||||
def test_period_and_conds():
|
||||
txt = "90 дней PRO бесплатно, без карты и без KYC"
|
||||
assert d.period(txt) == "90 дней"
|
||||
assert d.conds(txt) == "без карты, без KYC"
|
||||
|
||||
|
||||
def test_kind_grouping():
|
||||
assert d.kind({"tags": "keys,trial"}) == "keys"
|
||||
assert d.kind({"tags": ["accs"]}) == "accs"
|
||||
assert d.kind({"tags": ""}) == "tools"
|
||||
|
||||
|
||||
def test_card_render_offline():
|
||||
it = {
|
||||
"title": "**1 млн бесплатных токенов** на QWEN3.8-OMNI-FLASH",
|
||||
"text": "дают 1 млн токенов на 90 дней, без карты и без KYC, ключ по ссылке",
|
||||
"url": "https://example.com/post/1",
|
||||
"source": "demo_channel",
|
||||
"tags": "keys,trial",
|
||||
}
|
||||
html = chr(10).join(d.card(1, it))
|
||||
assert "<b>1." in html
|
||||
assert "1 млн" in html and "токенов" in html
|
||||
assert "на 90 дней" in html
|
||||
assert "без карты" in html
|
||||
assert "<a href=" in html and "пост" in html
|
||||
assert "**" not in html
|
||||
|
||||
|
||||
def test_build_renders():
|
||||
try:
|
||||
text = d.build(3)
|
||||
except Exception as exc: # sandbox без наполненной базы
|
||||
import pytest
|
||||
|
||||
pytest.skip(str(exc))
|
||||
assert "OMNI" in text and "КЛЮЧИ" in text.upper()
|
||||
assert len(text) <= 4000
|
||||
Reference in New Issue
Block a user