| 1 | |
| 2 | import os |
| 3 | import unittest |
| 4 | |
| 5 | import corpus |
| 6 | |
| 7 | from src.curriculum import load, load_from_vault |
| 8 | |
| 9 | BIO = os.path.join(os.path.dirname(corpus.book_path() or ""), "kazanimlar.json") |
| 10 | DATA = "data" |
| 11 | |
| 12 | |
| 13 | @unittest.skipUnless(os.path.exists(BIO), f"veri yok: {BIO}") |
| 14 | class CurriculumGraphTests(unittest.TestCase): |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | @classmethod |
| 22 | def setUpClass(cls): |
| 23 | yol, sinif, ders = corpus.find_book() |
| 24 | cls.sinif, cls.ders = sinif, ders |
| 25 | cls.g = load(BIO, sinif=sinif, ders=ders) |
| 26 | |
| 27 | def test_graph_is_not_empty(self): |
| 28 | self.assertGreater(len(self.g), 5) |
| 29 | |
| 30 | def test_units_are_grouped(self): |
| 31 | units = self.g.units() |
| 32 | self.assertTrue(units) |
| 33 | for uid, ad in units: |
| 34 | self.assertIsInstance(ad, str) |
| 35 | self.assertTrue(ad.strip(), "ünite adı boş") |
| 36 | |
| 37 | def test_every_objective_carries_its_scope(self): |
| 38 | for k in self.g.kazanimlar: |
| 39 | self.assertEqual(k.sinif, self.sinif) |
| 40 | self.assertEqual(k.ders, self.ders) |
| 41 | |
| 42 | def test_codes_are_unique_and_start_with_the_grade(self): |
| 43 | kodlar = [k.kod for k in self.g.kazanimlar if k.kod] |
| 44 | self.assertEqual(len(kodlar), len(set(kodlar)), "kazanım kodu tekrar ediyor") |
| 45 | for kod in kodlar: |
| 46 | self.assertTrue(kod.startswith(self.sinif + "."), |
| 47 | f"{kod} sınıf {self.sinif} ile başlamıyor") |
| 48 | |
| 49 | def test_lookup_by_code_round_trips(self): |
| 50 | kodlu = [k for k in self.g.kazanimlar if k.kod] |
| 51 | if not kodlu: |
| 52 | self.skipTest("kodlu kazanım yok") |
| 53 | ilk = kodlu[0] |
| 54 | self.assertIs(self.g.by_kod(ilk.kod), ilk) |
| 55 | |
| 56 | def test_unknown_code_returns_none(self): |
| 57 | self.assertIsNone(self.g.by_kod("99.9.9.9")) |
| 58 | |
| 59 | |
| 60 | @unittest.skipUnless(os.path.isdir(DATA), "veri yok") |
| 61 | class CurriculumVaultTests(unittest.TestCase): |
| 62 | def test_vault_merges_many_subjects(self): |
| 63 | g = load_from_vault(DATA) |
| 64 | |
| 65 | self.assertGreater(len(g), 100) |
| 66 | self.assertGreater(len(g.subjects()), 5) |
| 67 | |
| 68 | |
| 69 | if __name__ == "__main__": |
| 70 | unittest.main() |