DFiP_Budget_planing/perf/tests/test_svod2_paging_check.py
2026-10-29 00:23:34 +04:00

45 lines
1.6 KiB
Python

"""Самопроверка чистых функций svod2_paging_check (без стенда)."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "analysis"))
import svod2_paging_check as chk # noqa: E402
def _row(i, **data):
return {"row_type": "row", "depth": 0, "sort_order": i, "data": {"line_id": i, **data}}
def test_stitch_pages_seven_rows_limit_three():
rows = [_row(i) for i in range(7)]
calls = []
def fetch(offset, limit):
calls.append((offset, limit))
return {"result": rows[offset : offset + limit], "total": 7}
stitched, totals = chk.stitch_pages(fetch, 3)
assert stitched == rows
assert totals == {7}
def test_compare_stitched_catches_gap_and_duplicate():
full = [_row(i) for i in range(5)]
assert chk.compare_stitched(full, list(full)) == []
assert chk.compare_stitched(full, full[:2] + full[3:]) # пропуск
assert chk.compare_stitched(full, full[:3] + [full[2]] + full[3:]) # повтор
def test_check_compact_catches_extra_key_and_lost_zero():
full = [_row(1, header={"name": "x"}, plan={"plan_q1": 0, "plan_q2": 5})]
proj = chk.compact_projection(full[0]["data"])
assert proj["plan"]["plan_q1"] == 0
ok = [{"row_type": "row", "depth": 0, "sort_order": 1, "data": proj}]
assert chk.check_compact(full, ok) == []
extra = [{**ok[0], "data": {**proj, "zzz_extra": 1}}]
assert chk.check_compact(full, extra)
lost = [{**ok[0], "data": {**proj, "plan": {"plan_q2": 5}}}]
assert chk.check_compact(full, lost)
assert chk.check_compact(full, []) # потерянная строка