From d1fefa6b9ddbf76c878ed0e7f948ca29d0f27707 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh <39159+jcarbaugh@users.noreply.github.com> Date: Sat, 16 May 2026 19:59:24 -0700 Subject: [PATCH 1/2] add county tests and fix data --- us/states.py | 3 --- us/tests/test_us.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/us/states.py b/us/states.py index 4fdab72..59d9b5a 100644 --- a/us/states.py +++ b/us/states.py @@ -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"}), @@ -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"}), @@ -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"}), diff --git a/us/tests/test_us.py b/us/tests/test_us.py index bb446a9..addb33f 100644 --- a/us/tests/test_us.py +++ b/us/tests/test_us.py @@ -1,3 +1,4 @@ +import re from itertools import chain import jellyfish # type: ignore @@ -5,6 +6,7 @@ import pytz import us +from us.states import County # attribute @@ -154,3 +156,38 @@ 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) == "" + 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} " + f"not prefixed by state fips {state.fips}" + ) From eea3ddca974fc322641fc9eb56a81563282dfd9f Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh <39159+jcarbaugh@users.noreply.github.com> Date: Sat, 16 May 2026 20:05:11 -0700 Subject: [PATCH 2/2] fix formatting --- us/tests/test_us.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/us/tests/test_us.py b/us/tests/test_us.py index addb33f..ab667b4 100644 --- a/us/tests/test_us.py +++ b/us/tests/test_us.py @@ -188,6 +188,5 @@ 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} " - f"not prefixed by state fips {state.fips}" + f"{state.abbr}: county {county.name} fips {county.fips} not prefixed by state fips {state.fips}" )