| 1 | |
| 2 | import unittest |
| 3 | |
| 4 | from src.ingest.pdf_parse import Block, Page, HEADING, HEADER, PARAGRAPH |
| 5 | from src.ingest.isolate import (page_exclusion_reason, block_is_assessment, |
| 6 | block_is_question_options) |
| 7 | |
| 8 | |
| 9 | def _page(*blocks): |
| 10 | return Page(number=1, width=400, height=560, blocks=list(blocks)) |
| 11 | |
| 12 | |
| 13 | def _b(text, kind=PARAGRAPH): |
| 14 | return Block(page=1, bbox=(0, 0, 100, 20), text=text, block_no=0, kind=kind) |
| 15 | |
| 16 | |
| 17 | class QuestionOptionTests(unittest.TestCase): |
| 18 | def test_five_options_is_question(self): |
| 19 | self.assertTrue(block_is_question_options( |
| 20 | "Aşağıdakilerden hangisi? A) x B) y C) z D) w E) q")) |
| 21 | |
| 22 | def test_single_option_not_question(self): |
| 23 | self.assertFalse(block_is_question_options("A vitamini A) grubundadır")) |
| 24 | |
| 25 | def test_letter_inside_word_not_counted(self): |
| 26 | |
| 27 | self.assertFalse(block_is_question_options("mRNA) ve tRNA) yapıları")) |
| 28 | |
| 29 | def test_normal_paragraph_not_question(self): |
| 30 | self.assertFalse(block_is_question_options("DNA çift sarmal bir moleküldür.")) |
| 31 | |
| 32 | |
| 33 | class AssessmentTests(unittest.TestCase): |
| 34 | def test_assessment_markers(self): |
| 35 | self.assertTrue(block_is_assessment("Ünite Değerlendirme Soruları")) |
| 36 | self.assertTrue(block_is_assessment("ÖLÇME VE DEĞERLENDİRME")) |
| 37 | self.assertTrue(block_is_assessment("Öz Değerlendirme")) |
| 38 | |
| 39 | def test_normal_not_assessment(self): |
| 40 | self.assertFalse(block_is_assessment("Fotosentez kloroplastta gerçekleşir.")) |
| 41 | |
| 42 | |
| 43 | class PageExclusionTests(unittest.TestCase): |
| 44 | def test_kaynakca_heading_excluded(self): |
| 45 | self.assertEqual(page_exclusion_reason(_page(_b("KAYNAKÇA", HEADER))), "kaynakca") |
| 46 | |
| 47 | def test_icindekiler_excluded(self): |
| 48 | self.assertEqual(page_exclusion_reason(_page(_b("İÇİNDEKİLER", HEADING))), "icindekiler") |
| 49 | |
| 50 | def test_kitap_tanitimi_tr_lower(self): |
| 51 | |
| 52 | self.assertEqual(page_exclusion_reason(_page(_b("KİTAP TANITIMI", HEADER))), "kitap_tanitimi") |
| 53 | |
| 54 | def test_cevap_anahtari_in_body_not_excluded(self): |
| 55 | |
| 56 | pg = _page(_b("2. Ünite", HEADING), |
| 57 | _b("Soruların cevap anahtarı karekodda verilmiştir.", PARAGRAPH)) |
| 58 | self.assertIsNone(page_exclusion_reason(pg)) |
| 59 | |
| 60 | def test_teaching_page_not_excluded(self): |
| 61 | pg = _page(_b("1.2.2. Genetik Mühendisliği", HEADING), |
| 62 | _b("Genetik mühendisliği DNA'yı değiştirir.", PARAGRAPH)) |
| 63 | self.assertIsNone(page_exclusion_reason(pg)) |
| 64 | |
| 65 | |
| 66 | if __name__ == "__main__": |
| 67 | unittest.main() |