| 1 | |
| 2 | import os |
| 3 | import unittest |
| 4 | |
| 5 | import corpus |
| 6 | |
| 7 | from src.ingest.canonical import build_canonical |
| 8 | from src.chunk import chunk_document |
| 9 | |
| 10 | BOOK = corpus.book_path() |
| 11 | |
| 12 | |
| 13 | @corpus.requires_book |
| 14 | class Chunk12BioTests(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 | cls.chunks = chunk_document(cls.doc) |
| 19 | cls.children = [c for c in cls.chunks if c.level == "child"] |
| 20 | cls.parents = [c for c in cls.chunks if c.level == "parent"] |
| 21 | |
| 22 | def test_children_and_parents_produced(self): |
| 23 | self.assertGreater(len(self.children), 20) |
| 24 | self.assertGreater(len(self.parents), 5) |
| 25 | |
| 26 | def test_child_span_ids_exist_in_doc(self): |
| 27 | doc_spans = {u.span_id for u in self.doc.units} |
| 28 | child_spans = {sid for c in self.children for sid in c.span_ids} |
| 29 | self.assertTrue(child_spans.issubset(doc_spans)) |
| 30 | |
| 31 | self.assertEqual(child_spans, {u.span_id for u in self.doc.retrievable_units}) |
| 32 | |
| 33 | def test_children_linked_to_real_parents(self): |
| 34 | pids = {p.chunk_id for p in self.parents} |
| 35 | linked = [c for c in self.children if c.parent_id] |
| 36 | self.assertGreater(len(linked), 0) |
| 37 | for c in linked: |
| 38 | self.assertIn(c.parent_id, pids) |
| 39 | |
| 40 | def test_child_token_sizes_reasonable(self): |
| 41 | |
| 42 | big = [c for c in self.children if c.approx_tokens > 600] |
| 43 | self.assertLess(len(big), len(self.children) * 0.1) |
| 44 | |
| 45 | def test_chunks_have_provenance_and_meta(self): |
| 46 | for c in self.chunks[:100]: |
| 47 | self.assertTrue(c.span_ids) |
| 48 | self.assertTrue(c.text.strip()) |
| 49 | self.assertEqual((c.sinif, c.ders), (corpus.find_book()[1], corpus.find_book()[2])) |
| 50 | self.assertIn(c.page_visual, {"figure_heavy", "mixed", "low_visual"}) |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | unittest.main() |