Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions us/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ def mapping(from_field: str, to_field: str, states: Optional[Iterable[State]] =
"time_zones": ["America/Phoenix"],
"name_metaphone": "ARSN",
"counties": [
County(**{"fips": "STATEFPCOUNTYFP", "ns_code": "COUNTYNS", "name": "COUNTYNAME"}),
County(**{"fips": "04001", "ns_code": "00025441", "name": "Apache County"}),
County(**{"fips": "04003", "ns_code": "00025442", "name": "Cochise County"}),
County(**{"fips": "04005", "ns_code": "00025443", "name": "Coconino County"}),
Expand Down Expand Up @@ -524,7 +523,6 @@ def mapping(from_field: str, to_field: str, states: Optional[Iterable[State]] =
"time_zones": ["America/Denver"],
"name_metaphone": "KLRT",
"counties": [
County(**{"fips": "STATEFPCOUNTYFP", "ns_code": "COUNTYNS", "name": "COUNTYNAME"}),
County(**{"fips": "08001", "ns_code": "00198116", "name": "Adams County"}),
County(**{"fips": "08003", "ns_code": "00198117", "name": "Alamosa County"}),
County(**{"fips": "08005", "ns_code": "00198118", "name": "Arapahoe County"}),
Expand Down Expand Up @@ -1455,7 +1453,6 @@ def mapping(from_field: str, to_field: str, states: Optional[Iterable[State]] =
"time_zones": ["America/Chicago", "America/Denver"],
"name_metaphone": "KNSS",
"counties": [
County(**{"fips": "STATEFPCOUNTYFP", "ns_code": "COUNTYNS", "name": "COUNTYNAME"}),
County(**{"fips": "20001", "ns_code": "00484970", "name": "Allen County"}),
County(**{"fips": "20003", "ns_code": "00484971", "name": "Anderson County"}),
County(**{"fips": "20005", "ns_code": "00484972", "name": "Atchison County"}),
Expand Down
36 changes: 36 additions & 0 deletions us/tests/test_us.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
from itertools import chain

import jellyfish # type: ignore
import pytest # type: ignore
import pytz

import us
from us.states import County

# attribute

Expand Down Expand Up @@ -154,3 +156,37 @@ def test_contiguous():
def test_continental():
# Lower 48 + Alaska
assert len(us.STATES_CONTINENTAL) == 49


# counties


COUNTY_FIPS_RE = re.compile(r"^\d{5}$")


def test_county_class():
county = County(fips="01001", ns_code="00161526", name="Autauga County")
assert county.fips == "01001"
assert county.ns_code == "00161526"
assert county.name == "Autauga County"
assert repr(county) == "<County:Autauga County>"
assert str(county) == "Autauga County"


def test_every_state_has_counties():
for state in us.STATES_AND_TERRITORIES:
assert isinstance(state.counties, list), f"{state.abbr} has no counties"


def test_county_fips_format():
for state in us.STATES_AND_TERRITORIES:
for county in state.counties:
assert COUNTY_FIPS_RE.match(county.fips), f"{state.abbr}: bad county fips {county.fips!r}"


def test_county_fips_prefixed_by_state():
for state in us.STATES_AND_TERRITORIES:
for county in state.counties:
assert county.fips.startswith(state.fips), (
f"{state.abbr}: county {county.name} fips {county.fips} not prefixed by state fips {state.fips}"
)