File size: 2,013 Bytes
6ce7899
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""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):
        # G8 is absent from this run and never failed -- it left GUIDELINES.
        _chunks, preserved = self._preserve([], {"IRB-G4"})
        self.assertNotIn("IRB-G8", preserved)

    def test_act_code_matches_what_build_emits(self):
        # Pins the identity: the failed-set is built from g["num"], so the
        # two must agree or preservation silently never matches.
        for g in irb_guidelines.GUIDELINES:
            self.assertRegex(f"IRB-G{g['num']}", r"^IRB-G\w+$")


if __name__ == "__main__":
    unittest.main()