Skip to content

Commit

Permalink
Adding tests and removing unneeded regex
Browse files Browse the repository at this point in the history
  • Loading branch information
whubsch committed Jul 29, 2024
1 parent 5dbeecc commit 21cfef0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
16 changes: 7 additions & 9 deletions src/atlus/atlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ def mc_replace(value: str) -> str:
Returns:
str: Fixed string.
"""
mc_match = regex.search(r"(.*\bMc)([a-z])(.*)", value)
if mc_match:
return mc_match.group(1) + mc_match.group(2).title() + mc_match.group(3)
return value
words = []
for word in value.split():
mc_match = word.partition("Mc")
words.append(mc_match[0] + mc_match[1] + mc_match[2].capitalize())
return " ".join(words)


def ord_replace(value: str) -> str:
Expand Down Expand Up @@ -230,11 +231,7 @@ def abbrs(value: str) -> str:
)

# normalize 'US'
value = regex.sub(
r"\bU.[Ss].\B",
cap_match,
value,
)
value = us_replace(value)

# uppercase shortened street descriptors
value = regex.sub(
Expand Down Expand Up @@ -448,6 +445,7 @@ def get_address(
for each in bad_fields:
cleaned_ret.pop(each, None)

removed.extend(bad_fields)
validated: Address = Address.model_validate(cleaned_ret)

return validated.model_dump(exclude_none=True, by_alias=True), removed
Expand Down
28 changes: 17 additions & 11 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_mc_replace() -> None:
assert mc_replace("Mcmaster is a great leader") == "McMaster is a great leader"
assert mc_replace("Mcdonald's is popular") == "McDonald's is popular"
assert mc_replace("I like the Mcflurry") == "I like the McFlurry"
assert mc_replace("Mcflurry Mcmansion") == "McFlurry McMansion"
assert (
mc_replace("No Mc in this string") == "No Mc in this string"
) # No change expected
Expand Down Expand Up @@ -220,24 +221,29 @@ def test_get_address() -> None:
}


def test_get_address_removed() -> None:
def test_get_address_removed_unit() -> None:
"""Test cases for get address"""
add = get_address("222 NW Pineapple Ave Suite A Unit B, Beachville, SC 75309")
print(add)
assert add[0] == {
add, removed = get_address(
"222 NW Pineapple Ave Suite A Unit B, Beachville, SC 75309"
)
assert add == {
"addr:housenumber": "222",
"addr:street": "Northwest Pineapple Avenue",
"addr:city": "Beachville",
"addr:state": "SC",
"addr:postcode": "75309",
}
assert add[1] == ["addr:unit"]
# add = get_address("158 S. Thomas Court 30008 90210")
# assert add[0] == {
# "addr:housenumber": "158",
# "addr:street": "South Thomas Court",
# }
# assert add[1] == ["addr:postcode"]
assert removed == ["addr:unit"]


def test_get_address_removed_postcode() -> None:
"""Test cases for get address"""
add, removed = get_address("158 S. Thomas Court 30008 90210")
assert add == {
"addr:housenumber": "158",
"addr:street": "South Thomas Court",
}
assert removed == ["addr:postcode"]


def test_valid_phone_number_1() -> None:
Expand Down

0 comments on commit 21cfef0

Please sign in to comment.