diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index ca430af..d2f8adb 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -22,10 +22,10 @@ jobs:
python-version: "3.12"
- name: Install dependencies
- run: pip install pytest pydantic
+ run: pip install pytest usaddress regex
- name: Install package in editable mode
run: pip install -e .
- name: Run tests
- run: python -m pytest tests/test.py
+ run: python -m pytest tests/*
diff --git a/scripts/make_docs.py b/scripts/make_docs.py
index 9e66720..6b5b194 100644
--- a/scripts/make_docs.py
+++ b/scripts/make_docs.py
@@ -10,7 +10,7 @@
pdoc.render.configure(
docformat="google",
footer_text="atlus",
- favicon="https://whubsch.github.io/atlus/atlus_fav.svg",
- logo="https://whubsch.github.io/atlus/logo_blank.png",
+ favicon="https://whubsch.github.io/atlus_py/atlus_fav.svg",
+ logo="https://whubsch.github.io/atlus_py/logo_black.png",
)
pdoc.pdoc("src/atlus", output_directory=here.parent / "docs")
diff --git a/src/atlus/atlus.py b/src/atlus/atlus.py
index 181629c..e3a6dcd 100644
--- a/src/atlus/atlus.py
+++ b/src/atlus/atlus.py
@@ -22,7 +22,7 @@
"USPSBoxType",
"OccupancyType",
]
-"""Tags from the `usaddress` packageto remove."""
+"""Tags from the `usaddress` package to remove."""
osm_mapping = {
"AddressNumber": "addr:housenumber",
@@ -222,6 +222,15 @@ def grid_match(match_str: regex.Match) -> str:
def abbrs(value: str) -> str:
"""Bundle most common abbreviation expansion functions.
+ ```python
+ >> abbrs("St. Francis")
+ # "Saint Francis"
+ >> abbrs("E St.")
+ # "E Street"
+ >> abbrs("E Sewell St")
+ # "East Sewell Street"
+ ```
+
Args:
value (str): String to expand.
@@ -387,6 +396,13 @@ def process(
) -> tuple[OrderedDict[str, str | int], list[str | None]]:
"""Process address strings.
+ ```python
+ >> process("345 MAPLE RD, COUNTRYSIDE, PA 24680-0198")
+ # {"addr:housenumber": "345", "addr:street": "Maple Road", "addr:city": "Countryside", "addr:state": "PA", "addr:postcode": "24680-0198"}
+ >> process("777 Strawberry St.")
+ # {"addr:housenumber": "777", "addr:street": "Strawberry Street",}
+ ```
+
Args:
address_string (str): The address string to process.
diff --git a/tests/test.py b/tests/test.py
index 62fa9f3..f9b5b61 100644
--- a/tests/test.py
+++ b/tests/test.py
@@ -1,8 +1,25 @@
+# python3.12 -m pytest tests/*
+
+import pytest
from src.atlus.atlus import *
+def test_get_title():
+ """Test get_title function."""
+ assert get_title("PALM BEACH") == "Palm Beach"
+ assert get_title("BOSTON") == "BOSTON"
+ assert get_title("BOSTON", single_word=True) == "Boston"
+ assert get_title("NEW YORK CITY") == "New York City"
+ assert get_title("MCGREGOR") == "MCGREGOR" # Test with mock_mc_replace
+ assert (
+ get_title("MCGREGOR", single_word=True) == "McGregor"
+ ) # Test with mock_mc_replace and single_word=True
+ assert get_title("Some Mixed Case") == "Some Mixed Case" # No change expected
+ assert get_title("MiXeD cAsE") == "MiXeD cAsE" # No change expected
+
+
def test_us_replace():
- # Test cases for us_replace
+ """Test cases for us_replace"""
assert us_replace("U.S. Route 15") == "US Route 15"
assert us_replace("Traveling on U. S. Highway") == "Traveling on US Highway"
assert us_replace("U S Route is the best") == "US Route is the best"
@@ -11,7 +28,7 @@ def test_us_replace():
def test_mc_replace():
- # Test cases for mc_replace
+ """Test cases for mc_replace"""
assert mc_replace("Fort Mchenry") == "Fort McHenry"
assert mc_replace("Mcmaster is a great leader") == "McMaster is a great leader"
assert mc_replace("Mcdonald's is popular") == "McDonald's is popular"
@@ -22,11 +39,14 @@ def test_mc_replace():
def test_ord_replace():
+ """Test cases for ord_replace"""
assert ord_replace("December 4Th") == "December 4th"
assert ord_replace("3Rd St. NW") == "3rd St. NW"
+ assert ord_replace("1St of May") == "1st of May"
def test_street_expand():
+ """Test street cases for name_street_expand"""
assert (
abbr_join_comp.sub(
name_street_expand,
@@ -44,6 +64,7 @@ def test_street_expand():
def test_name_expand():
+ """Test name cases for name_street_expand"""
assert (
abbr_join_comp.sub(
@@ -54,11 +75,163 @@ def test_name_expand():
)
-# def test_direct_expand():
-# with pytest.raises(ValueError):
-# direct_expand(None)
+def test_direct_expand():
+ """Test direct_expand function"""
+ assert (
+ dir_fill_comp.sub(
+ direct_expand,
+ "N",
+ )
+ == "North"
+ )
+ assert (
+ dir_fill_comp.sub(
+ direct_expand,
+ "N Hyatt Rd.",
+ )
+ == "North Hyatt Rd."
+ )
+
+
+def test_replace_br_tags():
+ """Test cases to replace br tags"""
+ assert clean("Hello
World") == "Hello,World"
+ assert clean("Hello
World") == "Hello,World"
+
+
+def test_remove_unicode():
+ """Test cases for remove unicode"""
+ assert clean("Hello\u2014World") == "HelloWorld" # \u2014 is an em dash
+ assert clean("Café") == "Caf"
+
+
+def test_ascii_only():
+ """Test cases for ascii only"""
+ assert clean("Hello, World!") == "Hello, World!"
+
+
+def test_mixed_content():
+ """Test cases for mixed content"""
+ assert clean("Hello
World\u2014Café") == "Hello,WorldCaf"
+
+
+def test_empty_string():
+ """Test cases for empty string"""
+ assert clean("") == ""
+
+
+def test_basic_join():
+ """Test cases for basic join"""
+ tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
+ keep = ["street", "city"]
+ assert help_join(tags, keep) == "Main St Springfield"
+
+
+def test_keep_all():
+ """Test cases for keep all"""
+ tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
+ keep = ["street", "city", "zip"]
+ assert help_join(tags, keep) == "Main St Springfield 12345"
+
+
+def test_keep_none():
+ """Test cases for keep none"""
+ tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
+ keep = []
+ assert help_join(tags, keep) == ""
+
+
+def test_some_missing():
+ """Test cases for some missing keys"""
+ tags = {"street": "Main St", "city": "Springfield"}
+ keep = ["street", "city", "zip"]
+ assert help_join(tags, keep) == "Main St Springfield"
+
+
+def test_no_matching_keys():
+ """Test cases for no matching keys"""
+ tags = {"street": "Main St", "city": "Springfield"}
+ keep = ["zip"]
+ assert help_join(tags, keep) == ""
+
+
+def test_empty_tags():
+ """Test cases for empty tags"""
+ tags = {}
+ keep = ["street", "city"]
+ assert help_join(tags, keep) == ""
+
+
+def test_non_existent_keys():
+ """Test cases for non-existent keys"""
+ tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
+ keep = ["country", "state"]
+ assert help_join(tags, keep) == ""
+
+
+def test_remove_duplicates():
+ """Test cases for remove duplicates"""
+ assert collapse_list(["foo", "bar", "foo"]) == ["foo", "bar"]
+
+
+def test_no_duplicates():
+ """Test cases for no duplicates"""
+ assert collapse_list(["foo", "bar", "baz"]) == ["foo", "bar", "baz"]
+
+
+def test_empty_list():
+ """Test cases for empty list"""
+ assert collapse_list([]) == []
+
+
+def test_all_duplicates():
+ """Test cases for all duplicates"""
+ assert collapse_list(["foo", "foo", "foo"]) == ["foo"]
+
+
+def test_mixed_duplicates():
+ """Test cases for mixed duplicates"""
+ assert collapse_list(["foo", "bar", "baz", "foo", "bar"]) == ["foo", "bar", "baz"]
+
+
+def test_complex_data_types():
+ """Test cases for complex data types"""
+ assert collapse_list([1, 2, 1, 3, 4, 2, 5]) == [1, 2, 3, 4, 5]
+ assert collapse_list([(1, 2), (1, 2), (2, 3)]) == [(1, 2), (2, 3)]
+ assert collapse_list([1, "1", 1, "1"]) == [1, "1"]
+
+
+def test_valid_phone_number_1():
+ """Test cases for valid phone numbers"""
+ assert phone_format("2029009019") == "+1 202-900-9019"
+ assert phone_format("(202) 900-9019") == "+1 202-900-9019"
+ assert phone_format("202-900-9019") == "+1 202-900-9019"
+ assert phone_format("+1 202 900 9019") == "+1 202-900-9019"
+ assert phone_format("+1 (202) 900-9019") == "+1 202-900-9019"
+
+
+def test_invalid_phone_number_1():
+ """Test cases for invalid phone numbers"""
+ with pytest.raises(ValueError, match="Invalid phone number: 202-900-901"):
+ phone_format("202-900-901")
+
+
+def test_invalid_phone_number_2():
+ """Test cases for invalid phone numbers"""
+ with pytest.raises(ValueError, match="Invalid phone number: abc-def-ghij"):
+ phone_format("abc-def-ghij")
+
+
+def test_invalid_phone_number_3():
+ """Test cases for invalid phone numbers"""
+ with pytest.raises(ValueError, match="Invalid phone number: 12345"):
+ phone_format("12345")
+
-# assert direct_expand(regex.match("([NSWE])", "N")) == "North"
+def test_invalid_phone_number_4():
+ """Test cases for blank phone numbers"""
+ with pytest.raises(ValueError, match="Invalid phone number: "):
+ phone_format("")
# def test_cap_match():