Files
cobol-java-v3/test-data/_paths.py
T

48 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================================
# _paths.py — test-data 回归脚本统一路径解析(混合式)
#
# 优先级: 环境变量 → %USERPROFILE%\Desktop\2026技术大赛\ 兜底推导
# 缺失时在使用方通过 require() 得到清晰的设置指引。
# 环境变量说明见项目根 .env.example。
# ============================================================================
import os
import sys
from pathlib import Path
V3_ROOT = Path(__file__).resolve().parent.parent
_DESKTOP = Path(os.environ.get("USERPROFILE", "")) / "Desktop"
_CONTEST_ROOT = _DESKTOP / "2026技术大赛"
def _resolve(env_name: str, fallback: Path) -> Path:
if env_name in os.environ:
return Path(os.environ[env_name])
return fallback
def require(path, label: str, env_name: str) -> Path:
"""存在性检查,失败时给出环境变量设置指引。"""
p = Path(path)
if not p.exists():
sys.exit(
f"[错误] {label} 目录不存在: {p}\n"
f"请设置环境变量 {env_name} 指向实际目录"
f"(例: setx {env_name} \"D:\\...\"),或参见 .env.example"
)
return p
# 基准程序集(cobol-test-programs)— 本机当前布局中不存在,需 COBOL_BENCH_ROOT
BENCH_ROOT = _resolve("COBOL_BENCH_ROOT", _CONTEST_ROOT / "cobol-test-programs")
COPYBOOKS_BENCH = BENCH_ROOT / "common" / "copybooks"
# TNA 电信测试系统 — 当前布局位于大赛目录下
TNA_ROOT = _resolve("COBOL_TNA_ROOT", _CONTEST_ROOT / "cobol-tna-system")
COPYBOOKS_TNA = TNA_ROOT / "cpy"
# jcl-cobol-gitHINA 分类验证用旧仓库)
COBOL_GIT_ROOT = _resolve("COBOL_GIT_ROOT", _CONTEST_ROOT / "jcl-cobol-git")
# 散置样本源码
SAMPLE_SRC_DIR = _resolve("SAMPLE_SRC_DIR", _CONTEST_ROOT)