Skip to content

Commit

Permalink
Merge pull request #55 from argyle-engineering/support-mail-stop
Browse files Browse the repository at this point in the history
Support US mail stop
  • Loading branch information
lmelninkas authored Jul 8, 2024
2 parents 70379bd + 3115233 commit 0cb9b39
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyap/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Address:
country: Union[str, None] = None
route_id: Union[str, None] = None
occupancy: Union[str, None] = None
mail_stop: Union[str, None] = None
street_type: Union[str, None] = None
building_id: Union[str, None] = None
postal_code: Union[str, None] = None
Expand Down
9 changes: 9 additions & 0 deletions pyap/source_US/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,13 @@ def street_type_list_to_regex(street_type_list: list[str]) -> str:
)
"""

mail_stop = r"""
(?P<mail_stop>
# attention: do not to mix up with postal code
MSC?:?\s[A-Z]{,4}\s?\d{3,4}\b
)
"""

po_box = r"""
(?:
[Pp]\.?\ ?[Oo]\.?\ ?
Expand Down Expand Up @@ -968,6 +975,7 @@ def street_type_list_to_regex(street_type_list: list[str]) -> str:
(?:{part_div}{floor})?
(?:{part_div}{building})?
(?:{part_div}{occupancy})?
(?:{part_div}{mail_stop})?
(?:{part_div}(?P<po_box_a>{po_box}))?
)
|
Expand All @@ -984,6 +992,7 @@ def street_type_list_to_regex(street_type_list: list[str]) -> str:
floor=floor,
building=building,
occupancy=occupancy,
mail_stop=mail_stop,
po_box=po_box,
)

Expand Down
12 changes: 12 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,18 @@ def test_combine_results():
"postal_code": "67530",
},
),
(
"One Baylor Plaza MS: BCM204\nHouston TX 77030-3411",
{
"street_number": "One",
"street_type": "Plaza",
"street_name": "Baylor",
"mail_stop": "MS: BCM204",
"city": "Houston",
"region1": "TX",
"postal_code": "77030-3411",
},
),
],
)
def test_parse_address(input: str, expected):
Expand Down
19 changes: 19 additions & 0 deletions tests/test_parser_us.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,23 @@ def test_occupancy(input, expected):
execute_matching_test(input, expected, data_us.occupancy)


@pytest.mark.parametrize(
"input, expected",
[
# positive assertions
("MS CORP 003", True),
("MS: BCM204", True),
("MSC 1234", True),
("MS 1234", True),
# negative assertions
("MS 12345", False),
("MS CORP", False),
],
)
def test_mail_stop(input, expected):
execute_matching_test(input, expected, data_us.mail_stop)


@pytest.mark.parametrize(
"input,expected",
[
Expand Down Expand Up @@ -476,6 +493,8 @@ def test_full_street_positive(input, expected):
"input,expected",
[
# positive assertions
("One Baylor Plaza MS: BCM204\nHouston TX 77030-3411", True),
("ONE ADP DRIVE\nMS CORP 003\nAUGUSTA, GA 30909", True),
("2755 CARPENTER RD SUITE 1W\nANN ARBOR, MI, US, 48108", True),
("1111 3rd Street Promenade, Santa Monica, CA 90000", True),
("P.O. BOX 10323 PH (205) 595-3511\nBIRMINGHAM, AL 35202", True),
Expand Down

0 comments on commit 0cb9b39

Please sign in to comment.