Files
smeta-web/tests/test_arp.py
T
anorandClaude Opus 4.8 78f900660a feat: парсер .arp/.arps (АРПС 1.10, Smeta.RU) + MCP-tool + GLM-путь
Пункт 6 мастер-плана: .arp/.arps (294 файла) не читались. АРПС 1.10 — текстовый формат
(cp866, поля через '#'): тип 3=шапка (шифр/название/итог), тип 20=позиция (обоснование=
шифр, ед., наимен., стоимость). gge_tools.parse_arp_file + MCP-tool parse_arp_file +
.arp/.arps в ALLOWED обоих bridge + инлайн-чтение в GLM-пути. Объём-поле в АРПС неоднозначно —
по /sanity не выдумываю, беру надёжное (код/ед./наимен./итог). Юнит mutation-safe + серверный
real-тест на настоящем .arp (шифр 00-02-7-00-01Р, 70 позиций, итог 6.1М). APP_VERSION→2026-07-15f.

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

66 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Юнит-тест parse_arp_file на синтетическом АРПС 1.10 (cp866, поля через '#').
Реальный .arp — на сервере. Mutation-safe: сломай индекс поля кода → assert упадёт."""
import os
import sys
import tempfile
from pathlib import Path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from gge_tools import parse_arp_file
ARP = "\r\n".join([
"1#АРПС 1.10#Программный комплекс АВС#2022.2.1",
"0#Метод расчета#базисный#",
"3####00-02-7-00-01Р#Контактная сеть станции Находка#######Иванов#Петров#6105760,71#0",
"10#0#1# Строительные работы ",
"20#1#01-02-058-03 ОЕРЖ-2001 от 25.04.2015#100 м3 грунта#Копание ям вручную без креплений#4167,54#4167,54#0#0#0#0###411,0##43559,13#43559,13",
"25#4#0#0#1,3#Кзп#",
"20#2#28-02-013-01 ОЕРЖ-2001#1 опора#Установка опор с пути#100#100#0#0#0#0###5##2500,00#2500,00",
]) + "\r\n"
def _make_arp(d: Path) -> Path:
p = d / "смета.arp"
p.write_bytes(ARP.encode("cp866"))
return p
def test_header():
r = parse_arp_file(_make_arp(Path(tempfile.mkdtemp())))
assert "error" not in r, r
assert r["code"] == "00-02-7-00-01Р", r
assert r["name"] == "Контактная сеть станции Находка", r
assert abs(r["total"] - 6105760.71) < 0.01, r
def test_positions():
r = parse_arp_file(_make_arp(Path(tempfile.mkdtemp())))
assert r["positions_count"] == 2, r
p0 = r["positions"][0]
assert p0["code"] == "01-02-058-03", p0 # первый токен обоснования
assert p0["unit"] == "100 м3 грунта", p0
assert "Копание ям" in p0["name"], p0
assert abs(p0["total"] - 43559.13) < 0.01, p0
def test_bad_file():
d = Path(tempfile.mkdtemp())
p = d / "x.arp"
p.write_bytes(b"\xff\xfe not arps")
r = parse_arp_file(p)
# не падает; просто нет позиций/шапки
assert r["positions_count"] == 0, r
if __name__ == "__main__":
import traceback
fns = [v for k, v in sorted(globals().items()) if k.startswith("test_") and callable(v)]
failed = 0
for fn in fns:
try:
fn(); print(f" ok: {fn.__name__}")
except Exception:
failed += 1; print(f" FAIL: {fn.__name__}"); traceback.print_exc()
print("ALL PASS" if not failed else f"{failed} FAILED")
sys.exit(failed)