from __future__ import annotations from pathlib import Path from openpyxl import load_workbook from app.pipeline.mapping import FIXED_REPORT_COLUMNS from app.pipeline.report import ReportRow, write_report def test_write_report_streaming_preserves_header_and_formats(tmp_path: Path) -> None: destination = tmp_path / "report.xlsx" rows = [ ReportRow( file_name="SKO115FZ_01_123456789_20260616_X00001.xml", record_id="RID-1", operation_index=1, operation_fields={"СуммаОпер": "100.50", "ДатаОпер": "2026-06-16"}, participant_fields={}, ) ] write_report(rows, destination) workbook = load_workbook(destination) sheet = workbook["Отчет"] headers = [cell.value for cell in sheet[1]] assert headers == list(FIXED_REPORT_COLUMNS) row_values = [ sheet.cell(row=2, column=index).value for index in range(1, len(FIXED_REPORT_COLUMNS) + 1) ] assert "SKO115FZ_01_123456789_20260616_X00001.xml" in row_values date_col_idx = next( ( index for index, column in enumerate(FIXED_REPORT_COLUMNS, start=1) if "Дата" in column ), None, ) if date_col_idx is not None: assert sheet.cell(row=2, column=date_col_idx).number_format == "DD.MM.YYYY" sum_col_idx = next( ( index for index, column in enumerate(FIXED_REPORT_COLUMNS, start=1) if "Сумм" in column or "Сумма" in column ), None, ) if sum_col_idx is not None: assert sheet.cell(row=2, column=sum_col_idx).number_format == "#,##0.00"