gitlink-cli/skills/slidecast/tests/test_cast.py

89 lines
2.8 KiB
Python

"""slidecast 单元测试。"""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "scripts"))
import pytest
from cast import split_paper, extract_points, build_slides, render_markdown, _speaker_note
PAPER = """# 标题
## 引言
医学分割很重要。然而标注稀缺。本文提出对比学习方法。
## 方法
我们设计了预训练框架。该框架学习表征。
## 结果
结果表明方法显著优于基线。消融证明预训练贡献最大。
"""
class TestSplitPaper:
def test_sections(self):
secs = split_paper(PAPER)
titles = [s["title"] for s in secs]
assert "引言" in titles and "方法" in titles and "结果" in titles
def test_numeric_heading(self):
secs = split_paper("1. 引言\n这是引言内容很长一段。\n2. 方法\n这是方法内容。")
titles = [s["title"] for s in secs]
assert any("引言" in t for t in titles)
def test_bom(self):
secs = split_paper("\ufeff## 引言\n内容内容内容。")
assert secs
class TestExtractPoints:
def test_signal_words_prioritized(self):
body = "天气不错。我们提出了一种新方法。结果表明它很好。随便一句废话。"
pts = extract_points(body, max_points=2)
# 含信号词的句子应被选中
joined = "".join(pts)
assert "提出" in joined or "结果" in joined
def test_max_points(self):
body = "".join([f"我们提出方法{i}" for i in range(10)]) + ""
pts = extract_points(body, max_points=3)
assert len(pts) <= 3
def test_empty(self):
assert extract_points("") == []
def test_preserves_order(self):
body = "我们提出A。我们提出B。我们提出C。"
pts = extract_points(body, max_points=3)
assert pts.index("我们提出A。") < pts.index("我们提出B。")
class TestSpeakerNote:
def test_method_note(self):
assert "直觉" in _speaker_note("方法", [])
def test_result_note(self):
assert "结论" in _speaker_note("实验结果", [])
class TestBuildSlides:
def test_has_title_and_end(self):
data = build_slides(PAPER, title="测试汇报")
assert data["slides"][0]["type"] == "title"
assert data["slides"][-1]["type"] == "end"
def test_content_slides(self):
data = build_slides(PAPER)
content = [s for s in data["slides"] if s["type"] == "content"]
assert len(content) >= 3
def test_render(self):
md = render_markdown(build_slides(PAPER, title="X"))
assert "PPT 大纲" in md
assert "演讲备注" in md
assert "第 1 页" in md
if __name__ == "__main__":
sys.exit(pytest.main([__file__, "-v"]))