forge
Explore
Log in

Don't you dare go Hollow

hezarfen_rag

Clone
★ 0

0 watching0 forksPython2.4 MiB184b84dAhmet Kaan Gümüş2 months ago189 commits

test_chunk.py54 lines, 2.1 KiBHistoryRawDownload
1"""Faz 1.1 integration testi — 12-bio kanonik doküman üzerinde chunking (gerçek veri)."""
2import os
3import unittest
4
5import corpus
6
7from src.ingest.canonical import build_canonical
8from src.chunk import chunk_document
9
10BOOK = corpus.book_path()
11
12
13@corpus.requires_book
14class 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 # tüm retrievable birimler bir çocukta yer almalı
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 # çoğu çocuk üst sınırın çok üstünde olmamalı (tek dev birim istisnası olabilir)
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
53if __name__ == "__main__":
54 unittest.main()