test(review): 新增 pytest 离线回归网,锁定 dwg_review 既有行为
在改动审查流水线(确定性检查前置 / 结论结构化 / 证据交叉校验)之前, 先立一张离线、确定性、秒级的回归网。 - tests/fakes.py:假 LLM + 假 MCP 基座 + 响应构造器(ok_text/ok_image/err) + make_ctx/make_evidence,绝不触网、不读密钥 - 10 个模块共 134 用例: mcp_client / llm_client / cad_tools / checklist / config / planning / evidence / review / report / annotator - pytest.ini(testpaths=tests)+ requirements-dev.txt + 根 conftest.py (sys.path + RENDER_WAIT=0 / REPORT_DIR=tmp fixture)
This commit is contained in:
1 parent
8c07c7cad6
commit
0656397a68
15 files changed
+1710
No files matched your search
@@ -0,0 +1,68 @@
|
||||
"""`dwg_review.config` 单元测试(只验证纯函数与常量类型,不依赖真实环境变量)。"""
|
||||
|
||||
import os
|
||||
|
||||
from dwg_review import config
|
||||
|
||||
|
||||
def test_resolve_path_relative_uses_project_root():
|
||||
assert config._resolve_path("reports") == config.PROJECT_ROOT / "reports"
|
||||
|
||||
|
||||
def test_resolve_path_absolute_unchanged(tmp_path):
|
||||
assert config._resolve_path(str(tmp_path)) == tmp_path
|
||||
|
||||
|
||||
def test_project_root_is_repo_root():
|
||||
assert (config.PROJECT_ROOT / "dwg_review" / "config.py").is_file()
|
||||
|
||||
|
||||
def test_read_env_prefers_environ(monkeypatch):
|
||||
monkeypatch.setenv("CAD_TEST_ENV_PROBE", "hello")
|
||||
assert config._read_env("CAD_TEST_ENV_PROBE") == "hello"
|
||||
|
||||
|
||||
def test_read_env_missing_returns_empty(monkeypatch):
|
||||
monkeypatch.delenv("CAD_TEST_DEFINITELY_MISSING_XYZ", raising=False)
|
||||
assert config._read_env("CAD_TEST_DEFINITELY_MISSING_XYZ") == ""
|
||||
|
||||
|
||||
def test_has_api_key_reflects_module_value(monkeypatch):
|
||||
monkeypatch.setattr(config, "API_KEY", "")
|
||||
assert config.has_api_key() is False
|
||||
monkeypatch.setattr(config, "API_KEY", "sk-x")
|
||||
assert config.has_api_key() is True
|
||||
|
||||
|
||||
def test_has_api_key_ignores_whitespace(monkeypatch):
|
||||
monkeypatch.setattr(config, "API_KEY", " ")
|
||||
assert config.has_api_key() is False
|
||||
|
||||
|
||||
def test_constants_have_expected_types():
|
||||
assert isinstance(config.HOST, str)
|
||||
assert isinstance(config.PORT, int)
|
||||
assert isinstance(config.CALL_TIMEOUT, float)
|
||||
assert isinstance(config.CALL_RETRIES, int)
|
||||
assert isinstance(config.MAX_FRAME_BYTES, int)
|
||||
assert isinstance(config.IMAGE_MAX_EDGE, int)
|
||||
assert isinstance(config.IMAGE_FORMAT, str)
|
||||
assert isinstance(config.CHECKLIST_PATH, type(config.PROJECT_ROOT))
|
||||
|
||||
|
||||
def test_checklist_path_resolves_relative_to_root():
|
||||
assert config.CHECKLIST_PATH.name == "review_checklist.json"
|
||||
assert config.CHECKLIST_PATH.parent == config.PROJECT_ROOT
|
||||
|
||||
|
||||
def test_port_default_matches_baseline():
|
||||
# 基座固定监听 127.0.0.1:8080;若此值被改动,请同步更新基座与文档。
|
||||
assert config.HOST == "127.0.0.1"
|
||||
assert config.PORT == 8080
|
||||
|
||||
|
||||
def test_os_name_guard_in_read_env(monkeypatch):
|
||||
# 非 Windows 平台不应触碰注册表
|
||||
monkeypatch.setattr(os, "name", "posix")
|
||||
monkeypatch.delenv("CAD_TEST_ENV_PROBE2", raising=False)
|
||||
assert config._read_env("CAD_TEST_ENV_PROBE2") == ""
|
||||
Reference in new issue
Block a user