# -*- coding: utf-8 -*- """XQ0052 插件级端到端:按壳子的加载方式加载插件,用真实 WCF 跑一次 run()。 验证链路:插件 run() → SDK 挂载 → settle_window → export_member → 两份 Excel。 用法(项目根): .venv\\Scripts\\python.exe tests\\xq0052_湖畔储值卡\\plugin_e2e.py """ from __future__ import annotations import importlib.util import os import sys BASE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.abspath(os.path.join(BASE, "..", "..")) PLUGIN_DIR = os.path.join(ROOT, "plugins", "XQ0001-0100", "XQ0052 湖畔储值卡每日导出统计") sys.path.insert(0, os.path.join(ROOT, "desktop", "electron-shell", "python")) # webhost 包 sys.path.insert(0, os.path.join(ROOT, "libs", "hotel_report")) # 开发态 SDK class _Ctx: def __init__(self): self.lines = [] def log(self, msg, level="INFO"): self.lines.append(msg) print(f" [{level}] {msg}") def progress(self, pct): if int(pct) in (5, 50, 55, 100): print(f" [progress] {int(pct)}%") def load_plugin(): spec = importlib.util.spec_from_file_location( "xq0052_plugin", os.path.join(PLUGIN_DIR, "__init__.py"), submodule_search_locations=[PLUGIN_DIR]) mod = importlib.util.module_from_spec(spec) sys.modules["xq0052_plugin"] = mod spec.loader.exec_module(mod) return mod.PLUGINS[-1] def main() -> int: if hasattr(sys.stdout, "reconfigure"): sys.stdout.reconfigure(encoding="utf-8", errors="replace") plugin = load_plugin() print(f"插件:{plugin.id} {plugin.name} v{plugin.version}") out_dir = os.path.join(BASE, "out") os.makedirs(out_dir, exist_ok=True) ctx = _Ctx() res = plugin.run({"day": "", "save_dir": out_dir}, ctx) print("\n" + res["summary"]) print("\n产出:") ok = True for p in res.get("files") or []: size = os.path.getsize(p) / 1024 / 1024 if os.path.isfile(p) else 0 print(f" {os.path.basename(p)} {size:.2f} MB {'OK' if size else '✗ 缺失'}") ok &= bool(size) print(f"\n链路:{'OK' if ok else '✗'}") return 0 if ok else 2 if __name__ == "__main__": sys.exit(main())