From 868ee1331d7828cf25d839791cd820a97675cbb6 Mon Sep 17 00:00:00 2001 From: Hanna Torrence Date: Tue, 14 Jul 2026 11:08:03 -0500 Subject: [PATCH] add occupancy-first format for Canada --- pyap/source_CA/data.py | 14 +++++++++++++- tests/test_parser_ca.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/pyap/source_CA/data.py b/pyap/source_CA/data.py index e662c04..07e3323 100644 --- a/pyap/source_CA/data.py +++ b/pyap/source_CA/data.py @@ -377,6 +377,17 @@ )\ ? """ +unit_first_civic = r""" + (?: + (?\d{1,4}) + \ ?\-\ ? + (?P\d{1,5}) + (?=[\ ,\n])\ ? + ) + """ + po_box = r""" (?: # English - PO Box 123 @@ -444,7 +455,7 @@ (?P (?P - {street_number}\,?\ ? + (?:{unit_first_civic}|{street_number})\,?\ ? {street_name}?\,?\ ? (?:(?<=[\ \,]){street_type})\,?\ ? {post_direction}? @@ -476,6 +487,7 @@ floor=floor, building=building, occupancy=occupancy, + unit_first_civic=unit_first_civic, po_box=po_box, po_box_b=po_box_b, po_box_positive_lookahead=po_box_positive_lookahead, diff --git a/tests/test_parser_ca.py b/tests/test_parser_ca.py index 839e1e1..149f5a5 100644 --- a/tests/test_parser_ca.py +++ b/tests/test_parser_ca.py @@ -313,6 +313,44 @@ def test_occupancy_negative(input, expected): assert is_found == expected +@pytest.mark.parametrize( + "input,occupancy,street_number", + [ + ("200 - 5050 ", "200", "5050"), + ("108 - 1550 ", "108", "1550"), + ("202-121 ", "202", "121"), + ("104-18663 ", "104", "18663"), + ("#4-123 ", "4", "123"), + ], +) +def test_unit_first_civic_positive(input, occupancy, street_number): + """tests string match for the occupancy-first civic number format""" + match = utils.match( + data_ca.unit_first_civic, utils.unicode_str(input), re.VERBOSE + ) + assert match is not None + assert match.group("occupancy_c") == occupancy + assert match.group("street_number_c") == street_number + + +@pytest.mark.parametrize( + "input,expected", + [ + # negative assertions + ("718 - 8th ", False), + ("108-1550x ", False), + ("suite 900 ", False), + ], +) +def test_unit_first_civic_negative(input, expected): + """tests string match for the occupancy-first civic number format""" + match = utils.match( + data_ca.unit_first_civic, utils.unicode_str(input), re.VERBOSE + ) + is_found = match is not None + assert is_found == expected + + @pytest.mark.parametrize( "input,expected", [