45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
"""`dwg_review.context.ReviewContext` 单元测试(重点:离线模式不碰网络)。"""
|
|||
|
|
|
||
|
|
from dwg_review import evidence_model
|
||
|
|
from dwg_review.context import ReviewContext
|
||
|
|
|
||
|
|
|
||
|
|
def test_create_offline_has_no_client_or_tools():
|
||
|
|
"""connect_cad=False → client / tools 均为 None(不构造 CadTools,不连 8080)。"""
|
||
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False)
|
||
|
|
assert ctx.client is None
|
||
|
|
assert ctx.tools is None
|
||
|
|
assert ctx.llm is None
|
||
|
|
# 离线上下文仍应加载好清单(纯文件读取)
|
||
|
|
assert isinstance(ctx.checklist, dict)
|
||
|
|
|
||
|
|
|
||
|
|
def test_create_offline_default_source_is_cad():
|
||
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False)
|
||
|
|
assert ctx.source == evidence_model.SOURCE_CAD
|
||
|
|
|
||
|
|
|
||
|
|
def test_create_offline_explicit_source():
|
||
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False, source=evidence_model.SOURCE_PDF)
|
||
|
|
assert ctx.source == evidence_model.SOURCE_PDF
|
||
|
|
|
||
|
|
|
||
|
|
def test_create_offline_overrides_apply():
|
||
|
|
ctx = ReviewContext.create(
|
||
|
|
need_llm=False, connect_cad=False, max_frames=3, frame_limit=9, dry_run=True
|
||
|
|
)
|
||
|
|
assert ctx.max_frames == 3
|
||
|
|
assert ctx.frame_limit == 9
|
||
|
|
assert ctx.dry_run is True
|
||
|
|
|
||
|
|
|
||
|
|
def test_create_offline_does_not_connect(monkeypatch):
|
||
|
|
"""确保离线路径完全没有实例化 McpClient / CadTools(真连会抛 OSError)。"""
|
||
|
|
|
||
|
|
def _boom(*a, **k): # pragma: no cover - 被调用即失败
|
||
|
|
raise AssertionError("离线模式不应触碰 CAD 客户端")
|
||
|
|
|
||
|
|
monkeypatch.setattr("dwg_review.context.McpClient", _boom)
|
||
|
|
monkeypatch.setattr("dwg_review.context.CadTools", _boom)
|
||
|
|
ctx = ReviewContext.create(need_llm=False, connect_cad=False)
|
||
|
|
assert ctx.client is None and ctx.tools is None
|