| 1 | |
| 2 | import os |
| 3 | import re |
| 4 | import unittest |
| 5 | |
| 6 | import corpus |
| 7 | |
| 8 | from src.ingest.canonical import build_canonical |
| 9 | |
| 10 | BOOK = corpus.book_path() |
| 11 | |
| 12 | |
| 13 | @corpus.requires_book |
| 14 | class Canonical12BioTests(unittest.TestCase): |
| 15 | @classmethod |
| 16 | def setUpClass(cls): |
| 17 | cls.doc = build_canonical(BOOK, sinif=corpus.find_book()[1], ders=corpus.find_book()[2]) |
| 18 | |
| 19 | def test_ids(self): |
| 20 | self.assertRegex(self.doc.doc_id, r"^[0-9a-f]{12}$") |
| 21 | self.assertRegex(self.doc.source_version, r"^[0-9a-f]{64}$") |
| 22 | self.assertGreater(self.doc.page_count, 50) |
| 23 | |
| 24 | def test_units_and_isolation(self): |
| 25 | s = self.doc.summary |
| 26 | self.assertGreater(s["total"], 100) |
| 27 | self.assertGreater(s["retrievable"], 0) |
| 28 | self.assertLess(s["retrievable"], s["total"]) |
| 29 | self.assertEqual(s["retrievable"] + s["excluded"], s["total"]) |
| 30 | |
| 31 | def test_every_unit_has_provenance(self): |
| 32 | for u in self.doc.units[:200]: |
| 33 | self.assertTrue(u.span_id.startswith(self.doc.doc_id + "#")) |
| 34 | self.assertTrue(u.text.strip()) |
| 35 | x0, y0, x1, y1 = u.bbox |
| 36 | self.assertLess(x0, x1); self.assertLess(y0, y1) |
| 37 | self.assertEqual((u.sinif, u.ders), (corpus.find_book()[1], corpus.find_book()[2])) |
| 38 | |
| 39 | def test_text_normalized(self): |
| 40 | |
| 41 | self.assertFalse(any("\xad" in u.text or "" in u.text for u in self.doc.units)) |
| 42 | |
| 43 | def test_page_visual_classes_valid(self): |
| 44 | classes = {u.page_visual for u in self.doc.units} |
| 45 | self.assertTrue(classes.issubset({"figure_heavy", "mixed", "low_visual"})) |
| 46 | |
| 47 | def test_zero_leak_excluded_pages(self): |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | sayfalar = {u.page for u in self.doc.units} |
| 57 | haric = {p for p in sayfalar |
| 58 | if not any(u.page == p and u.retrievable for u in self.doc.units)} |
| 59 | self.assertTrue(haric, "hiçbir sayfa hariç tutulmamış — izolasyon çalışmıyor") |
| 60 | for pno in sorted(haric): |
| 61 | sizan = [u for u in self.doc.units if u.page == pno and u.retrievable] |
| 62 | self.assertFalse(sizan, f"sayfa {pno}: {len(sizan)} birim sızdı") |
| 63 | |
| 64 | def test_span_id_stable_across_runs(self): |
| 65 | again = build_canonical(BOOK, sinif=corpus.find_book()[1], ders=corpus.find_book()[2]) |
| 66 | self.assertEqual(again.doc_id, self.doc.doc_id) |
| 67 | |
| 68 | |
| 69 | if __name__ == "__main__": |
| 70 | unittest.main() |