| """Unit tests for the IRB Chairperson's Guidelines ingester. Offline only. |
| |
| build() rebuilds irb_guidelines.json from a fresh fetch of three canada.ca |
| pages, so a template change or a dropped connection would delete a guideline |
| outright -- the failure mode that emptied dmemos.json on 2026-07-27. The write |
| guard itself is covered by tests/test_common.py; these cover this module's |
| identity and failed-set. |
| """ |
| import unittest |
|
|
| from canlex import _common, irb_guidelines |
|
|
|
|
| class GuidelineIdentityTests(unittest.TestCase): |
| STORED = [{"act_code": "IRB-G4", "text": "gender considerations"}, |
| {"act_code": "IRB-G4", "text": "part two"}, |
| {"act_code": "IRB-G8", "text": "vulnerable persons"}] |
|
|
| def _preserve(self, chunks, failed): |
| return _common.preserve_dropped(chunks, self.STORED, |
| key=lambda c: c["act_code"], |
| only=failed) |
|
|
| def test_a_failed_guideline_keeps_its_stored_chunks(self): |
| chunks, preserved = self._preserve([], {"IRB-G4"}) |
| self.assertEqual(preserved, ["IRB-G4"]) |
| self.assertEqual(len(chunks), 2) |
|
|
| def test_a_guideline_that_succeeded_is_not_resurrected(self): |
| chunks, preserved = self._preserve( |
| [{"act_code": "IRB-G4", "text": "fresh"}], {"IRB-G4"}) |
| self.assertEqual(preserved, []) |
| self.assertEqual(len(chunks), 1) |
|
|
| def test_a_guideline_dropped_on_purpose_stays_gone(self): |
| |
| _chunks, preserved = self._preserve([], {"IRB-G4"}) |
| self.assertNotIn("IRB-G8", preserved) |
|
|
| def test_act_code_matches_what_build_emits(self): |
| |
| |
| for g in irb_guidelines.GUIDELINES: |
| self.assertRegex(f"IRB-G{g['num']}", r"^IRB-G\w+$") |
|
|
|
|
| if __name__ == "__main__": |
| unittest.main() |
|
|