# -*- coding: utf-8 -*- """临时校验:目标变更记录表只认当天业务日期。""" import importlib import os import shutil import sys import tempfile from datetime import date, timedelta _REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.join(_REPO, "desktop", "electron-shell", "python")) sys.path.insert(0, os.path.join(_REPO, "plugins", "XQ0001-0100")) cfg = importlib.import_module("XQ0002 雇主险增减操作.config") today = date.today() yesterday = today - timedelta(days=1) root = tempfile.mkdtemp() folder = os.path.join(root, "三十七度") os.makedirs(folder) def touch(name): p = os.path.join(folder, name) with open(p, "wb") as f: f.write(b"x") return p old = touch(f"三十七度-雇主险变更记录-{yesterday.strftime('%Y.%m.%d')}.xlsx") old2 = touch("三十七度-雇主险变更记录-7.23.xlsx") try: cfg.find_target_file(folder) print("FAIL: 只有历史文件时未报错") except FileNotFoundError as e: print("PASS: 只有历史文件时报错 ->", str(e)[:90]) today_file = touch(f"三十七度-雇主险变更记录-{today.strftime('%Y.%m.%d')}.xlsx") picked = cfg.find_target_file(folder) print("PASS" if picked == today_file else "FAIL", ": 命中当天文件 ->", os.path.basename(picked)) cfg.set_base_dir(root) cat = cfg.get_category("三十七度") print("PASS" if cfg.category_target_file(cat) == today_file else "FAIL", ": category_target_file 同口径") pad = touch(f"三十七度-雇主险变更记录-{today.year}.{today.month}.{today.day}.xlsx") print("PASS" if cfg.find_target_file(folder).endswith(pad.split(os.sep)[-1]) else "FAIL", ": 不补零当天文件也可识别") os.remove(pad) shutil.rmtree(root, ignore_errors=True)