Files
smeta-web/tests/test_formats_server.py
T
anorandClaude Opus 4.8 3e9d832e19 feat: GLM-путь читает .xls/.doc/.gsfx, таблицы .docx, OCR PDF-сканов, честный отказ .esw
Пункты 3,4,5,7,8 (GLM-путь _read_work_dir_files): .xls через xlrd (openpyxl BIFF не умеет);
.doc через catdoc; .docx теперь с ТАБЛИЦАМИ (сметные docx = таблицы, GLM их упускал);
.gsfx инлайн через parse_gsfx_file; PDF-скан (fitz дал <40 симв) → OCR tesseract-rus;
.esw/.oew/.cew/.bma → честный отказ «экспортируйте в АРПС/Excel», не тихий пропуск.
Хост-инструменты доставлены (xlrd/docx уже были; catdoc+pytesseract поставлены; tesseract+rus).
Real-тест на настоящих файлах: .xls(2125 строк)/.doc/.docx/.gsfx/.esw + OCR скана (2063 симв).
APP_VERSION→2026-07-15e.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-15 20:58:05 +10:00

66 lines
2.7 KiB
Python

"""Real-тест чтения форматов в GLM-пути (_read_work_dir_files) на НАСТОЯЩИХ файлах
из загруженных архивов (гонять на dev2, где стоят xlrd/catdoc/tesseract/docx).
Вытаскивает по одному образцу .xls/.doc/.docx/.gsfx/.esw и проверяет вывод."""
import shutil
import sys
import tempfile
import zipfile
from pathlib import Path
from claude_bridge_glm import _read_work_dir_files
BASE = Path("/home/mcp-user/smeta-web-data/smeta/b1f47437-2254-4267-a584-4d2ea050e100")
# (архив, расширение, имя-образца)
SAMPLES = [
("40_Калинина.zip", ".xls", "sample.xls"),
("!_ТЗ ДЛЯ.zip", ".doc", "sample.doc"),
("!_ТЗ ДЛЯ.zip", ".docx", "sample.docx"),
("АРХИВ ОБЩИЙ_Гранд-смета.zip", ".gsfx", "sample.gsfx"),
("очистные тумнин.zip", ".esw", "sample.esw"),
]
tmp = Path(tempfile.mkdtemp())
got = {}
for arch, ext, outname in SAMPLES:
ap = BASE / arch
if not ap.exists():
print(f" ПРОПУСК {arch} (нет)")
continue
with zipfile.ZipFile(ap) as z:
entry = next((n for n in z.namelist()
if n.lower().endswith(ext) and not n.endswith("/")), None)
if not entry:
print(f" в {arch} нет {ext}")
continue
(tmp / outname).write_bytes(z.read(entry))
got[ext] = outname
out = _read_work_dir_files(tmp)
print("=== вывод _read_work_dir_files (обрезано) ===")
for line in out.splitlines():
if line.startswith("###") or "проприетарный" in line or "не удалось" in line:
print(" " + line[:110])
fails = 0
def chk(name, cond, hint=""):
global fails
print((" ok: " if cond else " FAIL: ") + name + ("" if cond else f" — {hint}"))
if not cond:
fails += 1
if ".xls" in got:
chk(".xls читается (xlrd)", "Лист:" in out and "не удалось" not in out.split("sample.xls")[1][:200], "нет данных листа")
if ".doc" in got:
seg = out.split("sample.doc")[1][:400] if "sample.doc" in out else ""
chk(".doc читается (catdoc)", "не удалось" not in seg and len(seg.strip()) > 20, "пустой/ошибка")
if ".docx" in got:
chk(".docx читается", "sample.docx" in out, "нет вывода")
if ".gsfx" in got:
chk(".gsfx парсится (Смета)", "Смета .gsfx" in out and "Шифр:" in out, "не распознан")
if ".esw" in got:
chk(".esw честный отказ", "проприетарный" in out, "нет отказа")
shutil.rmtree(tmp, ignore_errors=True)
print("ALL PASS" if not fails else f"{fails} FAILED")
sys.exit(fails)