Skip to content

Commit 58843f7

Browse files
committed
upgrading dependencies and improving tests
1 parent e8ee548 commit 58843f7

4 files changed

Lines changed: 62 additions & 19 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
"License :: OSI Approved :: MIT License",
2525
"Typing :: Typed",
2626
]
27-
dependencies = ["usaddress>=0.5.10", "regex>=2024.4.16"]
27+
dependencies = ["usaddress>=0.5.15", "regex>=2024.11.6"]
2828

2929
[project.urls]
3030
Documentation = "https://whubsch.github.io/atlus/index.html"

src/atlus/atlus.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Functions and tools to process the raw address strings."""
22

33
from collections import Counter
4-
from typing import Dict, List, Tuple, Union
54

65
import regex
76
import usaddress
@@ -262,7 +261,7 @@ def clean_address(address_string: str) -> str:
262261
"", remove_br_unicode(address_string).replace(" ", " ").strip(" ,.")
263262
)
264263
address_string = paren_comp.sub("", address_string)
265-
return grid_comp.sub(grid_match, address_string)
264+
return grid_comp.sub(grid_match, address_string).strip(" ,.")
266265

267266

268267
def help_join(tags, keep: list[str]) -> str:

src/atlus/objects.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Define objects for parsing fields."""
22

3-
from typing import Optional, Union
43

54
from pydantic import BaseModel, Field
65

tests/test.py

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,6 @@ def test_address_creation_invalid_state() -> None:
512512
)
513513

514514

515-
def test_address_creation_invalid_postcode() -> None:
516-
"""Test creation with invalid postcode"""
517-
with pytest.raises(ValidationError):
518-
Address(
519-
**{
520-
"addr:housenumber": "1200-29",
521-
"addr:street": "North Spring Street",
522-
"addr:unit": "B",
523-
"addr:city": "Los Angeles",
524-
"addr:state": "CA",
525-
"addr:postcode": "9001", # Invalid postcode
526-
}
527-
)
528-
529-
530515
def test_address_creation_optional_fields() -> None:
531516
"""Test creation with optional fields missing"""
532517
address = Address(**{"addr:housenumber": 200, "addr:street": "North Spring Street"})
@@ -556,3 +541,63 @@ def test_address_alias_handling() -> None:
556541
assert address.addr_city == "Los Angeles"
557542
assert address.addr_state == "CA"
558543
assert address.addr_postcode == "90012"
544+
545+
546+
def test_address_model_aliases():
547+
"""Test Address model field aliases."""
548+
addr = Address(**{"addr:housenumber": "123", "addr:street": "Main St"})
549+
550+
# Test model_dump with aliases
551+
dumped = addr.model_dump(exclude_none=True, by_alias=True)
552+
assert "addr:housenumber" in dumped
553+
assert "addr:street" in dumped
554+
assert dumped["addr:housenumber"] == "123"
555+
assert dumped["addr:street"] == "Main St"
556+
557+
# Test creation with invalid state (too long)
558+
with pytest.raises(ValidationError):
559+
Address(
560+
**{
561+
"addr:housenumber": "1200-29",
562+
"addr:street": "North Spring Street",
563+
"addr:unit": "B",
564+
"addr:city": "Los Angeles",
565+
"addr:state": "CAL", # Invalid state
566+
"addr:postcode": "90012-4801",
567+
}
568+
)
569+
570+
571+
def test_collapse_list_preserves_order():
572+
"""Test that collapse_list preserves the order of first occurrence."""
573+
input_list = ["c", "a", "b", "a", "c", "d"]
574+
expected = ["c", "a", "b", "d"]
575+
assert collapse_list(input_list) == expected
576+
577+
578+
def test_address_creation_invalid_postcode() -> None:
579+
"""Test creation with invalid postcode"""
580+
with pytest.raises(ValidationError):
581+
Address(
582+
**{
583+
"addr:housenumber": "1200-29",
584+
"addr:street": "North Spring Street",
585+
"addr:unit": "B",
586+
"addr:city": "Los Angeles",
587+
"addr:state": "CA",
588+
"addr:postcode": "9001", # Invalid postcode
589+
}
590+
)
591+
592+
593+
def test_get_address_comprehensive_cleaning():
594+
"""Test get_address with comprehensive address cleaning."""
595+
# Test address that exercises multiple cleaning functions
596+
test_address = "123A Main St., Apt B, New York, NY 12345-0000"
597+
result, removed = get_address(test_address)
598+
599+
assert result["addr:housenumber"] == "123"
600+
assert result["addr:unit"] == "A"
601+
assert "Main" in result["addr:street"]
602+
assert "Street" in result["addr:street"]
603+
assert result["addr:postcode"] == "12345" # Should remove -0000

0 commit comments

Comments
 (0)