feat: 修复代码审核报告问题
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""打分模块测试"""
|
||||
from datetime import datetime
|
||||
|
||||
from app.scorer import compute_heat_score, compute_importance_score, compute_duplication_score, compute_composite_score, score_articles
|
||||
from models import EnrichedArticle, Taxonomy, DuplicateGroup
|
||||
|
||||
|
||||
def test_compute_heat_score():
|
||||
rules = [Taxonomy(name="AI", kind="heat_rule", keywords=["AI", "大模型"], weight=1.5)]
|
||||
article = EnrichedArticle(title="OpenAI 发布 GPT-5 大模型")
|
||||
score = compute_heat_score(article, rules)
|
||||
assert score > 0
|
||||
|
||||
|
||||
def test_compute_importance_score():
|
||||
rules = [Taxonomy(name="政策", kind="importance_rule", keywords=["政策", "监管"], weight=2.0)]
|
||||
article = EnrichedArticle(title="新政策发布,加强 AI 监管")
|
||||
score = compute_importance_score(article, rules)
|
||||
assert score > 0
|
||||
|
||||
|
||||
def test_compute_duplication_score():
|
||||
assert compute_duplication_score(1) == 0.0
|
||||
assert compute_duplication_score(5) == 100.0
|
||||
|
||||
|
||||
def test_compute_composite_score():
|
||||
score = compute_composite_score(50, 80, 30)
|
||||
expected = 50 * 0.3 + 80 * 0.5 + 30 * 0.2
|
||||
assert score == round(expected, 2)
|
||||
|
||||
|
||||
def test_score_articles_integration(db):
|
||||
db.add_all([
|
||||
Taxonomy(name="AI", kind="heat_rule", keywords=["AI"], weight=1.5),
|
||||
Taxonomy(name="政策", kind="importance_rule", keywords=["政策"], weight=2.0),
|
||||
])
|
||||
article = EnrichedArticle(rk_article_id=1, title="AI 新政策发布")
|
||||
db.add(article)
|
||||
db.commit()
|
||||
|
||||
score_articles(db, article_ids=[article.id])
|
||||
|
||||
assert article.heat_score > 0
|
||||
assert article.importance_score > 0
|
||||
assert article.composite_score > 0
|
||||
Reference in New Issue
Block a user