Files
document_analyzer/tests/test_sample.py
T
pzhang_zywl d68c45a762
CI / test (push) Failing after 26s
test: add deliberate failure to verify CI pipeline
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-29 20:31:41 +08:00

95 lines
3.1 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_generator():
"""ir_generator module should be importable."""
os.environ.setdefault("DASHSCOPE_API_KEY", "test-fake-key")
_import_from_skill("ir_generation_skill", "ir_generator")
import ir_generator
assert hasattr(ir_generator, "generate_ir")
# -- 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__)),
"skills", "ir_generation_skill",
"车机娱乐系统禁止功能文档_精简_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")
def test_deliberate_failure():
"""This test is designed to fail - for CI failure verification."""
assert 1 == 2, "Deliberate failure to test CI pipeline"