Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pyap/source_CA/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@
)\ ?
"""

unit_first_civic = r"""
(?:
(?<![\.0-9])
\#?
(?P<occupancy_c>\d{1,4})
\ ?\-\ ?
(?P<street_number_c>\d{1,5})
(?=[\ ,\n])\ ?
)
"""

po_box = r"""
(?:
# English - PO Box 123
Expand Down Expand Up @@ -444,7 +455,7 @@
(?P<full_street>

(?P<line1>
{street_number}\,?\ ?
(?:{unit_first_civic}|{street_number})\,?\ ?
{street_name}?\,?\ ?
(?:(?<=[\ \,]){street_type})\,?\ ?
{post_direction}?
Expand Down Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions tests/test_parser_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down