| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import json
- import sys
- from pathlib import Path
- def test_extract_state_summary_accepts_dominant_key(tmp_path):
- scripts_dir = Path(__file__).resolve().parents[2]
- if str(scripts_dir) not in sys.path:
- sys.path.insert(0, str(scripts_dir))
- from extract_chapter_context import extract_state_summary
- state = {
- "progress": {"current_chapter": 12, "total_words": 12345},
- "protagonist_state": {
- "power": {"realm": "筑基", "layer": 2},
- "location": "宗门",
- "golden_finger": {"name": "系统", "level": 1},
- },
- "strand_tracker": {
- "history": [
- {"chapter": 10, "dominant": "quest"},
- {"chapter": 11, "dominant": "fire"},
- ]
- },
- }
- webnovel_dir = tmp_path / ".webnovel"
- webnovel_dir.mkdir(parents=True, exist_ok=True)
- (webnovel_dir / "state.json").write_text(json.dumps(state, ensure_ascii=False), encoding="utf-8")
- text = extract_state_summary(tmp_path)
- assert "Ch10:quest" in text
- assert "Ch11:fire" in text
|