Coverage for tests/test.py: 100%
114 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-27 13:56 -0400
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-27 13:56 -0400
1# python3.12 -m pytest tests/*
3import pytest
4from src.atlus.atlus import *
7def test_get_title():
8 """Test get_title function."""
9 assert get_title("PALM BEACH") == "Palm Beach"
10 assert get_title("BOSTON") == "BOSTON"
11 assert get_title("BOSTON", single_word=True) == "Boston"
12 assert get_title("NEW YORK CITY") == "New York City"
13 assert get_title("MCGREGOR") == "MCGREGOR" # Test with mock_mc_replace
14 assert (
15 get_title("MCGREGOR", single_word=True) == "McGregor"
16 ) # Test with mock_mc_replace and single_word=True
17 assert get_title("Some Mixed Case") == "Some Mixed Case" # No change expected
18 assert get_title("MiXeD cAsE") == "MiXeD cAsE" # No change expected
21def test_us_replace():
22 """Test cases for us_replace"""
23 assert us_replace("U.S. Route 15") == "US Route 15"
24 assert us_replace("Traveling on U. S. Highway") == "Traveling on US Highway"
25 assert us_replace("U S Route is the best") == "US Route is the best"
26 assert us_replace("This is the US") == "This is the US" # No change expected
27 assert us_replace("United States") == "United States" # No change expected
30def test_mc_replace():
31 """Test cases for mc_replace"""
32 assert mc_replace("Fort Mchenry") == "Fort McHenry"
33 assert mc_replace("Mcmaster is a great leader") == "McMaster is a great leader"
34 assert mc_replace("Mcdonald's is popular") == "McDonald's is popular"
35 assert mc_replace("I like the Mcflurry") == "I like the McFlurry"
36 assert (
37 mc_replace("No Mc in this string") == "No Mc in this string"
38 ) # No change expected
41def test_ord_replace():
42 """Test cases for ord_replace"""
43 assert ord_replace("December 4Th") == "December 4th"
44 assert ord_replace("3Rd St. NW") == "3rd St. NW"
45 assert ord_replace("1St of May") == "1st of May"
48def test_street_expand():
49 """Test street cases for name_street_expand"""
50 assert (
51 abbr_join_comp.sub(
52 name_street_expand,
53 "Hollywood Blvd",
54 )
55 == "Hollywood Boulevard"
56 )
57 assert (
58 abbr_join_comp.sub(
59 name_street_expand,
60 "Homer Dr.",
61 )
62 == "Homer Drive"
63 )
66def test_name_expand():
67 """Test name cases for name_street_expand"""
69 assert (
70 abbr_join_comp.sub(
71 name_street_expand,
72 "Intl Dr.",
73 )
74 == "International Drive"
75 )
78def test_direct_expand():
79 """Test direct_expand function"""
80 assert (
81 dir_fill_comp.sub(
82 direct_expand,
83 "N",
84 )
85 == "North"
86 )
87 assert (
88 dir_fill_comp.sub(
89 direct_expand,
90 "N Hyatt Rd.",
91 )
92 == "North Hyatt Rd."
93 )
96def test_replace_br_tags():
97 """Test cases to replace br tags"""
98 assert clean("Hello<br/>World") == "Hello,World"
99 assert clean("Hello<br />World") == "Hello,World"
102def test_remove_unicode():
103 """Test cases for remove unicode"""
104 assert clean("Hello\u2014World") == "HelloWorld" # \u2014 is an em dash
105 assert clean("Café") == "Caf"
108def test_ascii_only():
109 """Test cases for ascii only"""
110 assert clean("Hello, World!") == "Hello, World!"
113def test_mixed_content():
114 """Test cases for mixed content"""
115 assert clean("Hello<br/>World\u2014Café") == "Hello,WorldCaf"
118def test_empty_string():
119 """Test cases for empty string"""
120 assert clean("") == ""
123def test_basic_join():
124 """Test cases for basic join"""
125 tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
126 keep = ["street", "city"]
127 assert help_join(tags, keep) == "Main St Springfield"
130def test_keep_all():
131 """Test cases for keep all"""
132 tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
133 keep = ["street", "city", "zip"]
134 assert help_join(tags, keep) == "Main St Springfield 12345"
137def test_keep_none():
138 """Test cases for keep none"""
139 tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
140 keep = []
141 assert help_join(tags, keep) == ""
144def test_some_missing():
145 """Test cases for some missing keys"""
146 tags = {"street": "Main St", "city": "Springfield"}
147 keep = ["street", "city", "zip"]
148 assert help_join(tags, keep) == "Main St Springfield"
151def test_no_matching_keys():
152 """Test cases for no matching keys"""
153 tags = {"street": "Main St", "city": "Springfield"}
154 keep = ["zip"]
155 assert help_join(tags, keep) == ""
158def test_empty_tags():
159 """Test cases for empty tags"""
160 tags = {}
161 keep = ["street", "city"]
162 assert help_join(tags, keep) == ""
165def test_non_existent_keys():
166 """Test cases for non-existent keys"""
167 tags = {"street": "Main St", "city": "Springfield", "zip": "12345"}
168 keep = ["country", "state"]
169 assert help_join(tags, keep) == ""
172def test_remove_duplicates():
173 """Test cases for remove duplicates"""
174 assert collapse_list(["foo", "bar", "foo"]) == ["foo", "bar"]
177def test_no_duplicates():
178 """Test cases for no duplicates"""
179 assert collapse_list(["foo", "bar", "baz"]) == ["foo", "bar", "baz"]
182def test_empty_list():
183 """Test cases for empty list"""
184 assert collapse_list([]) == []
187def test_all_duplicates():
188 """Test cases for all duplicates"""
189 assert collapse_list(["foo", "foo", "foo"]) == ["foo"]
192def test_mixed_duplicates():
193 """Test cases for mixed duplicates"""
194 assert collapse_list(["foo", "bar", "baz", "foo", "bar"]) == ["foo", "bar", "baz"]
197def test_complex_data_types():
198 """Test cases for complex data types"""
199 assert collapse_list([1, 2, 1, 3, 4, 2, 5]) == [1, 2, 3, 4, 5]
200 assert collapse_list([(1, 2), (1, 2), (2, 3)]) == [(1, 2), (2, 3)]
201 assert collapse_list([1, "1", 1, "1"]) == [1, "1"]
204def test_get_address():
205 """Test cases for get address"""
206 assert get_address("345 MAPLE RD, COUNTRYSIDE, PA 24680-0198")[0] == {
207 "addr:housenumber": "345",
208 "addr:street": "Maple Road",
209 "addr:city": "Countryside",
210 "addr:state": "PA",
211 "addr:postcode": "24680-0198",
212 }
213 assert get_address("777 Strawberry St.")[0] == {
214 "addr:housenumber": "777",
215 "addr:street": "Strawberry Street",
216 }
219def test_get_address_removed():
220 """Test cases for get address"""
221 add = get_address("222 NW Pineapple Ave Suite A Unit B, Beachville, SC 75309")
222 assert add[0] == {
223 "addr:housenumber": "222",
224 "addr:street": "Northwest Pineapple Avenue",
225 "addr:city": "Beachville",
226 "addr:state": "SC",
227 "addr:postcode": "75309",
228 }
229 assert add[1] == ["addr:unit"]
230 # add = get_address("158 S. Thomas Court 30008 90210")
231 # assert add[0] == {
232 # "addr:housenumber": "158",
233 # "addr:street": "South Thomas Court",
234 # }
235 # assert add[1] == ["addr:postcode"]
238def test_valid_phone_number_1():
239 """Test cases for valid phone numbers"""
240 assert get_phone("2029009019") == "+1 202-900-9019"
241 assert get_phone("(202) 900-9019") == "+1 202-900-9019"
242 assert get_phone("202-900-9019") == "+1 202-900-9019"
243 assert get_phone("+1 202 900 9019") == "+1 202-900-9019"
244 assert get_phone("+1 (202) 900-9019") == "+1 202-900-9019"
247def test_invalid_phone_number_1():
248 """Test cases for invalid phone numbers"""
249 with pytest.raises(ValueError, match="Invalid phone number: 202-900-901"):
250 get_phone("202-900-901")
253def test_invalid_phone_number_2():
254 """Test cases for invalid phone numbers"""
255 with pytest.raises(ValueError, match="Invalid phone number: abc-def-ghij"):
256 get_phone("abc-def-ghij")
259def test_invalid_phone_number_3():
260 """Test cases for invalid phone numbers"""
261 with pytest.raises(ValueError, match="Invalid phone number: 12345"):
262 get_phone("12345")
265def test_invalid_phone_number_4():
266 """Test cases for blank phone numbers"""
267 with pytest.raises(ValueError, match="Invalid phone number: "):
268 get_phone("")