提取 collect/formatters/themes 等 pipeline 模块,新增 wecom 分条、RSS、delta、Agent 工作流测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
|
|
|
|
def _sample_github_repo() -> dict:
|
|
return {
|
|
"repo": "owner/sample",
|
|
"url": "https://github.com/owner/sample",
|
|
"description": "Sample repository for smoke tests.",
|
|
"language": "Python",
|
|
"stars_today_fmt": "120",
|
|
"total_stars_fmt": "1.2K",
|
|
"created_at": "2026-06-01",
|
|
}
|
|
|
|
|
|
def test_format_installs():
|
|
from shared.skills_data import format_installs
|
|
|
|
assert format_installs(999) == "999"
|
|
assert format_installs(18000) == "18.0K"
|
|
assert format_installs(2_500_000) == "2.5M"
|
|
|
|
|
|
def test_generate_report_offline(
|
|
skills_feed,
|
|
fixed_cst,
|
|
isolated_output,
|
|
offline_generate_env,
|
|
monkeypatch,
|
|
):
|
|
import daily.generate as generate
|
|
import daily.pipeline.collect as collect
|
|
|
|
monkeypatch.setattr(collect, "load_feed", lambda force=False: skills_feed)
|
|
monkeypatch.setattr(collect, "fetch_github_trending", lambda n: [_sample_github_repo()])
|
|
monkeypatch.setattr(collect, "fetch_emerging_repos", lambda n, exclude=None: [])
|
|
monkeypatch.setattr(collect, "fetch_topic_hot_repos", lambda n, exclude=None: ("llm", []))
|
|
monkeypatch.setattr(generate, "_now_cst", lambda: fixed_cst)
|
|
|
|
_, wecom_md, out_md, out_wecom = generate.generate_report()
|
|
|
|
assert out_md.exists()
|
|
assert out_wecom.exists()
|
|
assert "早报" in out_md.read_text(encoding="utf-8")
|
|
assert wecom_md.strip()
|
|
assert "📰" in wecom_md
|
|
|
|
data_path = isolated_output / "2026-07-03.data.json"
|
|
assert data_path.exists()
|
|
payload = json.loads(data_path.read_text(encoding="utf-8"))
|
|
assert payload["meta"]["report_mode"] == "classic"
|
|
assert payload["data"]["date"] == "2026-07-03"
|
|
assert len(payload["data"]["skills_trending"]) >= 1
|
|
assert len(payload["data"]["skills_hot"]) >= 1
|
|
|
|
|
|
def test_rss_fixture_is_well_formed():
|
|
xml = (FIXTURES / "sample-rss.xml").read_text(encoding="utf-8")
|
|
assert "Sample AI headline" in xml
|
|
assert "<item>" in xml
|