# -*- coding: utf-8 -*- """Ti-1 质量预测 sanity 检查(无构建环境下的离线基本验证)。 检查项: 1. 默认特征清单 features.template.yaml 可加载且通过校验; 2. 特征 source/denominator 的点位都在默认点位字典内; 3. 全部测试用例通过。 用法:python _sanity_check.py 退出码:0 全通过,非 0 有失败。 """ import os import sys import unittest HERE = os.path.dirname(os.path.abspath(__file__)) TESTS = os.path.join(HERE, "tests") def main() -> int: failures = [] # 1) 加载特征清单并校验点位 try: sys.path.insert(0, TESTS) import _bootstrap # noqa: F401 挂载 quality_forecast from quality_forecast import features as F ti_cl4 = os.path.dirname(HERE) pd = F.PointDict.from_csv( os.path.join(ti_cl4, "point-dict", "point_dict.default.csv")) with open(os.path.join(HERE, "config", "features.template.yaml"), "r", encoding="utf-8") as fh: ext = F.load_feature_specs(fh.read(), pd) if not ext.names: failures.append("特征清单为空") except Exception as exc: # noqa: BLE001 failures.append(f"特征清单加载失败: {exc}") # 2) 跑测试 loader = unittest.TestLoader() suite = loader.discover(TESTS, pattern="test_*.py") runner = unittest.TextTestRunner(verbosity=1) result = runner.run(suite) if not result.wasSuccessful(): failures.append(f"{len(result.failures)} 失败, {len(result.errors)} 错误") if failures: print("\n[sanity] 失败:") for f in failures: print(" -", f) return 1 print("\n[sanity] 全部通过") return 0 if __name__ == "__main__": sys.exit(main())