Files
document_analyzer/tests/test_sample.py
T
pzhang_zywl 884848f15f
CI / test (pull_request) Successful in 7s
fix: 统一输出文件目录结构 - Closes #3
- 新增 PROJECT_OUTPUT (项目根/output/),统一所有输出文件
- IR 中间产物 → output/ir/,最终交付物 → output/final/
- agent_poller.py 新增 pr-status/merge-pr/close-issue/lifecycle 命令
- DEV_AGENT.md 同步更新完整闭环流程
- 更新 conftest/test_sample 中的默认路径

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 14:38:37 +08:00

95 lines
3.0 KiB
Python

"""Minimal smoke tests for the document_analyzer pipeline."""
import os
import sys
import json
import pytest
# -- Helpers ------------------------------------------------------------------
def _import_from_skill(skill_name, module_name):
"""Import a module from a skill's scripts directory."""
skill_dir = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"skills", skill_name, "scripts"
)
if skill_dir not in sys.path:
sys.path.insert(0, skill_dir)
# -- WordParser tests (no LLM dependency) -------------------------------------
def test_import_word_parser():
"""word_parser module should be importable."""
_import_from_skill("doc_parser_skill", "word_parser")
import word_parser
assert hasattr(word_parser, "WordParser")
def test_import_image_parser():
"""image_parser module should be importable."""
_import_from_skill("doc_parser_skill", "image_parser")
import image_parser
assert hasattr(image_parser, "ImageParser")
def test_import_LLM():
"""LLM module should be importable (requires DASHSCOPE_API_KEY env var)."""
os.environ.setdefault("DASHSCOPE_API_KEY", "test-fake-key")
_import_from_skill("doc_parser_skill", "LLM")
import LLM
assert hasattr(LLM, "LLMClient")
# -- Conflict detection tests -------------------------------------------------
def test_import_detect_conflicts():
"""detect_conflicts module should be importable."""
os.environ.setdefault("DASHSCOPE_API_KEY", "test-fake-key")
_import_from_skill("conflict_detection_skill", "detect_conflicts")
import detect_conflicts
assert hasattr(detect_conflicts, "detect_conflicts")
# -- IR generation tests ------------------------------------------------------
def test_import_ir_main():
"""ir_generation main module should be importable (new project structure)."""
os.environ.setdefault("DASHSCOPE_API_KEY", "test-fake-key")
skill_dir = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"skills", "ir_generation_skill"
)
if skill_dir not in sys.path:
sys.path.insert(0, skill_dir)
import main
assert hasattr(main, "main")
# -- Resolution application tests ---------------------------------------------
def test_import_apply_resolutions():
"""apply_resolutions module should be importable."""
_import_from_skill("resolution_application_skill", "apply_resolutions")
import apply_resolutions
assert hasattr(apply_resolutions, "apply_resolutions")
# -- JSON output validation ---------------------------------------------------
def test_sample_ir_json_is_valid():
"""The sample IR JSON file should be valid JSON."""
sample_path = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
"output",
"车机娱乐系统禁止功能文档_精简_updated.json"
)
if os.path.exists(sample_path):
with open(sample_path, "r", encoding="utf-8") as f:
data = json.load(f)
assert isinstance(data, (dict, list))
else:
pytest.skip("Sample IR JSON not found")