# -*- coding: utf-8 -*- """测试引导:把 `core/template-console` 以包名 `template_console` 挂载到 sys.modules。 目录名 `template-console` 含连字符,无法直接以包名 import;挂载后模块内 相对导入(`from .rbac import ...`)在 unittest 发现机制下可正常解析。 同时把兄弟内核目录 `core/edge-gateway` 加入 sys.path,使 point_importer 可复用其 `point_dict` 子包(loader/validator/schema),避免重复造轮子。 """ import os import sys import types # 1) 挂载 core/template-console 为 template_console 包 CONSOLE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.insert(0, CONSOLE_DIR) if "template_console" not in sys.modules: pkg = types.ModuleType("template_console") pkg.__path__ = [CONSOLE_DIR] sys.modules["template_console"] = pkg # 2) 暴露兄弟内核 edge-gateway/point_dict(#63 复用其校验器) CORE_DIR = os.path.dirname(CONSOLE_DIR) EDGE_GW_DIR = os.path.join(CORE_DIR, "edge-gateway") if os.path.isdir(EDGE_GW_DIR) and EDGE_GW_DIR not in sys.path: sys.path.insert(0, EDGE_GW_DIR)