""" Comparison test: engine output vs the sample `Accounts Receivable Aging (Jan-26) 1.xlsx`. Extracts the sample's cached Detail/Summary cells and asserts the engine reproduces the USA figures to the penny. Integration (reads large sample files); run with -m integration. """ from __future__ import annotations from datetime import date import pytest from app.core.pipeline import process from app.core.compare import compare_to_sample, read_cached_cells, list_sheets pytestmark = pytest.mark.integration RESERVES = {("USA", "Standard Orders"): 125.44, ("USA", "Invoiced Orders"): 0.0} @pytest.fixture(scope="module") def result(jan_files): return process(jan_files, month_end=date(2026, 1, 31), clearing_lag_days=2, reserves=RESERVES) def test_detail_cells_match_sample(result, sample_workbook): diffs = compare_to_sample(result, sample_workbook, tolerance=1.0) report = "\n".join( f" Detail!{d.cell:<4} {d.label:<45} expected={d.expected} generated={d.generated} " f"diff={d.difference} [{d.status}]" for d in diffs ) print("\nCOMPARISON REPORT\n" + report) diffed = [d for d in diffs if d.status == "DIFF"] assert not diffed, f"cells differ from sample:\n{report}" def test_summary_usa_matches_sample(result, sample_workbook): sm = read_cached_cells(sample_workbook, "Summary", {"B11"}) usa = result.receivable.marketplaces["USA"] assert usa.receivable_usd == pytest.approx(sm["B11"], abs=1.0) # 11,110,433 def test_sample_has_expected_sheets(sample_workbook): sheets = list_sheets(sample_workbook) assert sheets[:3] == ["Summary", "Detail", "COA"] # the sample splits USA into two tabs — our generator mirrors that split assert any(s.startswith("USA") for s in sheets)