| """Unit tests for the staleness-check logic (canlex/refresh.py). Offline only.""" |
| import unittest |
|
|
| from canlex import refresh |
|
|
|
|
| class ExtractCurrentDateTests(unittest.TestCase): |
| def test_reads_root_attribute(self): |
| head = (b'<?xml version="1.0"?>\n<Statute xmlns:lims="..." ' |
| b'lims:current-date="2026-03-31" lims:lastAmendedDate="2026-03-26">') |
| self.assertEqual(refresh._extract_current_date(head), "2026-03-31") |
|
|
| def test_strips_utf8_bom(self): |
| head = b'\xef\xbb\xbf<Regulation lims:current-date="2019-06-21">' |
| self.assertEqual(refresh._extract_current_date(head), "2019-06-21") |
|
|
| def test_returns_empty_when_absent(self): |
| self.assertEqual(refresh._extract_current_date(b"<Statute foo='bar'>"), "") |
|
|
| def test_takes_the_current_date_not_amended_date(self): |
| |
| head = b'<Statute lims:lastAmendedDate="2099-01-01" lims:current-date="2026-05-26">' |
| self.assertEqual(refresh._extract_current_date(head), "2026-05-26") |
|
|
|
|
| class PendingInForceTests(unittest.TestCase): |
| def test_surfaces_a_bill_once_its_date_passes(self): |
| |
| after = refresh.pending_in_force("2026-08-01") |
| self.assertTrue(any(b["bill"] == "C-16" for b in after)) |
|
|
| def test_hides_a_bill_before_its_date(self): |
| before = refresh.pending_in_force("2026-07-01") |
| self.assertFalse(any(b["bill"] == "C-16" for b in before)) |
|
|
|
|
| class CbsaInstrumentRegexTests(unittest.TestCase): |
| def test_extracts_dated_instruments_from_index_html(self): |
| html = ('<a href="delegation/irpa-lipr-2023-05-08-eng.html">base</a>' |
| '<a href="delegation/irpa-lipr-2025-07-10-eng.html">amend</a>' |
| '<a href="desig/po-ag_2022-08-eng.html">peace officer</a>') |
| found = sorted(set(refresh._CBSA_INSTRUMENT_RE.findall(html))) |
| self.assertEqual(found, ["2023-05-08", "2025-07-10"]) |
| |
| self.assertNotIn("2022-08", "".join(found)) |
|
|
| def test_new_instrument_is_the_set_difference(self): |
| have = ["2023-05-08", "2025-07-10"] |
| published = ["2023-05-08", "2025-07-10", "2026-02-01"] |
| self.assertEqual(sorted(set(published) - set(have)), ["2026-02-01"]) |
|
|
| def test_il3_version_stamp_regex(self): |
| m = refresh._IL3_VERSION_RE.search("IL 3 ... Fall 2025 ... Operational") |
| self.assertEqual(m.group(0), "Fall 2025") |
|
|
|
|
| class DriftSemanticsTests(unittest.TestCase): |
| def test_iso_date_string_compare_detects_newer_upstream(self): |
| |
| self.assertTrue("2026-05-26" > "2026-03-31") |
| self.assertFalse("2026-03-31" > "2026-03-31") |
|
|
|
|
| if __name__ == "__main__": |
| unittest.main() |
|
|