42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""抽取章节知识:章后抽取 lesson 离线钉死。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pathlib
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[3]
|
|
SCRIPT = ROOT / "muse" / "content" / "entity" / "skills" / "extract" / "抽取章节知识" / "scripts"
|
|
EVIDENCE = ROOT / "muse" / "authority" / "evidence" / "skills" / "记录运行证据" / "scripts"
|
|
for path in (SCRIPT, EVIDENCE):
|
|
if str(path) not in sys.path:
|
|
sys.path.insert(0, str(path))
|
|
|
|
from extract_knowledge import _propose_chapter_extract_lesson # noqa: E402
|
|
|
|
|
|
class ChapterExtractLessonOfflineTest(unittest.TestCase):
|
|
def test_registers_win(self):
|
|
calls: list[dict] = []
|
|
|
|
def fake(**kwargs):
|
|
calls.append(kwargs)
|
|
return {"status": "proposed", "lesson_id": 3, "deduped": False}
|
|
|
|
with patch("extract_knowledge.propose_lesson_dedup", side_effect=fake):
|
|
out = _propose_chapter_extract_lesson(
|
|
run_id="run-ch-9", work_id=1, chapter_order=9,
|
|
draft_count=4, state_draft_id=99,
|
|
)
|
|
self.assertEqual(out["lesson_id"], 3)
|
|
self.assertEqual(calls[0]["kind"], "win")
|
|
self.assertEqual(calls[0]["title"], "章后知识抽取落库成功")
|
|
self.assertEqual(calls[0]["detail"]["chapter_order"], 9)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|