- scripts/expand_real_dataset.py:AutoWeakS 全量 2215 条 + 500 条分层评测集 + 简历扩量(seed=2026 可复现) - pipeline 被动语料机制(passive_sources):真实无日期 JD 参与接入/清洗/抽取验证(2915 条命中率 99.8%),不进图谱/演化/发现 - 新岗位发现第四指标'差异度'与双年窗口增长率口径 - 评测新增 real_jd_500 维度(99.91%);测试会话隔离 jd_extra_dirs 防止本机配置拖慢套件
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
"""pytest 共享夹具:确保数据与图谱存在(数据已随工程提交,缺失时现场生成)。"""
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
PY = sys.executable
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def ensure_data() -> None:
|
|
if not (ROOT / "data" / "jd_raw").exists():
|
|
subprocess.run([PY, str(ROOT / "scripts" / "generate_dataset.py")], check=True)
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def graph_path() -> Path:
|
|
path = ROOT / "data" / "graph.json"
|
|
if not path.exists():
|
|
subprocess.run([PY, str(ROOT / "scripts" / "run_demo.py")], check=True)
|
|
return path
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def isolated_state_db(tmp_path_factory):
|
|
"""整个测试会话把 SQLite 状态库重定向到临时目录,避免污染真实 data/careernexus.db。
|
|
|
|
audit_path/pending_path 仅作为旧文件迁移种子,指向不存在的临时路径即跳过迁移。
|
|
"""
|
|
from app.api import routes
|
|
tmp = tmp_path_factory.mktemp("state_db")
|
|
keys = ("state_db_path", "audit_path", "pending_path")
|
|
originals = {k: routes._cfg.get(k) for k in keys}
|
|
routes._cfg["state_db_path"] = str(tmp / "state.db")
|
|
routes._cfg["audit_path"] = str(tmp / "audit.jsonl")
|
|
routes._cfg["pending_path"] = str(tmp / "pending.json")
|
|
# 测试不加载本机附加数据源:真实语料会让 API 触发的重建超出任务等待窗口
|
|
extra_orig = routes._cfg.get("jd_extra_dirs")
|
|
routes._cfg["jd_extra_dirs"] = ""
|
|
yield
|
|
for k, v in originals.items():
|
|
if v is None:
|
|
routes._cfg.pop(k, None)
|
|
else:
|
|
routes._cfg[k] = v
|
|
if extra_orig is None:
|
|
routes._cfg.pop("jd_extra_dirs", None)
|
|
else:
|
|
routes._cfg["jd_extra_dirs"] = extra_orig
|