"""Stres testinde (pilot/) bulunan hatalar için regresyon testleri.""" import sqlite3 import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT)) from t2s.extract import ResolvedTable, extract_html, resolve # noqa: E402 from t2s.pipeline import merge_continuations # noqa: E402 from t2s.schema import TOTAL_RE, build_table, column_name, connect, write_table # noqa: E402 from t2s.trnum import fold # noqa: E402 def _rt(caption, page, body, src="a.pdf", hdr=(["Ad"], ["Değer"])): return ResolvedTable(caption, [list(h) for h in hdr], body, src, page, "test") def test_parantezli_yil_korunur(): assert column_name(["Nüfus (2025)"], 0) == "nufus_2025" assert column_name(["Ücret (TL)"], 0) == "ucret" def test_il_toplami_toplam_satiri(): assert TOTAL_RE.search(fold("İl Toplamı")) assert TOTAL_RE.search(fold("Genel Toplam")) assert not TOTAL_RE.search(fold("Toplamı bilinmeyen kalem a")) def test_sayfalara_bolunmus_tablo_birlesir_uc_sayfa(): parts = [_rt("Tablo 6: Mahalleler", 1, [["A", "1"]]), _rt("", 2, [["B", "2"]]), _rt("", 3, [["C", "3"]]), _rt("Tablo 7: Başka", 4, [["D", "4"]])] out = merge_continuations(parts) assert len(out) == 2 and [r[0] for r in out[0].body] == ["A", "B", "C"] def test_farkli_baslikli_ardisik_tablo_birlesmez(): out = merge_continuations([_rt("Bilanço", 1, [["A", "1"]]), _rt("Kar veya Zarar Tablosu", 2, [["B", "2"]])]) assert len(out) == 2 def test_adsiz_tablolar_birbirinin_uzerine_yazilmaz(tmp_path): con = connect(tmp_path / "t.db") n1 = write_table(con, build_table(_rt("", 1, [["A", "1"]], src="x.pdf"))) n2 = write_table(con, build_table(_rt("", 3, [["B", "2"]], src="y.pdf"))) assert n1 != n2 and "sutun" not in (n1, n2) assert {t for (t,) in con.execute("SELECT tablo FROM _tablolar")} == {n1, n2} def test_ayni_adli_iki_tablo_ayni_sayfada_korunur(tmp_path): con = connect(tmp_path / "t.db") a = write_table(con, build_table(_rt("Tablo 1: Satışlar", 1, [["A", "1"]]))) b = write_table(con, build_table(_rt("Tablo 2: Satışlar", 1, [["B", "2"]]))) assert a != b # aynı tablo yeniden aktarılırsa kendi yerine yazılır, kopya oluşmaz b2 = write_table(con, build_table(_rt("Tablo 2: Satışlar", 1, [["B", "3"]]))) assert b2 == b and con.execute("SELECT COUNT(*) FROM _tablolar").fetchone()[0] == 2 def test_tfoot_veri_sayilmaz(): html = ("
| İl | Değer |
|---|---|
| A | 1 |
| Kaynak: Y | |