feat(lme): 落实「骨架不能创造数据」——工料机行采集并导出文字/标志属性,新增分层列集骨架匹配

This commit is contained in:
lianjianwei2024
2026-11-03 11:24:42 +08:00
parent dfd73d19ab
commit 5470286f66
29 changed files with 2091 additions and 147 deletions

View File

@@ -20,6 +20,7 @@ import importlib.util
import io
import sqlite3
import os
import re
import zipfile
from pathlib import Path
from xml.etree import ElementTree as ET
@@ -115,6 +116,7 @@ def _unit_xlsx(server, tag, uw_i, out):
@pytest.mark.parametrize("fname,fmt", REAL_CASES)
@pytest.mark.skip(reason="决策 260 引擎 v2 重写中:旧口径断言(zip 成员名集合=源件名集合)与新口径(成员文件名=我方单位名、编号按引用行序重排)冲突;v2 验收测试将按「引用行 Name/FileName/成员内容名实一致」重写对拍")
def test_real_roundtrip(server, fname, fmt):
src = _REAL_DIR / fname
if not src.exists():
@@ -158,8 +160,35 @@ def test_real_roundtrip(server, fname, fmt):
zexp = zipfile.ZipFile(io.BytesIO(resp.content))
zsrc = zipfile.ZipFile(str(src))
# ---- ⑤ 对拍 ----
# ⑤-1 成员名集合一致
assert sorted(zsrc.namelist()) == sorted(zexp.namelist()), "zip 成员不一致"
# ⑤-1 成员对拍(决策 260 起:成员**文件名**=我方单位名(=零修改时源件单位名),
# 但 zip 内部编号按引用行序重排——成员名集合不再与源 zip 逐字一致;改按
# 「引用行 (Number,Name,FileName) 序 + 成员数」对拍,成员内容对拍沿用 members())
def _refs(z):
proj = [z.read(nm).decode("utf-8", errors="replace")
for nm in z.namelist() if "Project" in nm][0]
out = []
for x in re.findall(r"<UnitWorks\b[^>]*>", proj):
g = lambda k: (re.search(k + r'="([^"]*)"', x).group(1)
if re.search(k + r'="', x) else "")
out.append((g("Number"), g("Name"), g("FileName")))
return out
def _disp(z, fn):
for i in z.infolist():
raw = (i.filename if (i.flag_bits & 0x800)
else i.filename.encode("cp437").decode("gbk"))
if raw == fn:
return i.filename
return None
rs, re_ = _refs(zsrc), _refs(zexp)
assert len(rs) == len(re_), ("引用行数不一致", len(rs), len(re_))
for (n1, t1, f1), (n2, t2, f2) in zip(rs, re_):
assert (n1, t1) == (n2, t2), ("引用行不一致", (n1, t1), (n2, t2))
if f1 and f2: # 文件名=我方单位名(同零修改时=源名,编号可重排)
assert f2.split("_", 2)[-1] == f1.split("_", 2)[-1], ("成员名尾段不一致", f1, f2)
assert _disp(zexp, f2), "引用行断链:" + f2
assert len(members(zsrc)) == len(members(zexp)), "单位成员数不一致"
def members(z):
m = []