Skip to content
Open
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
6 changes: 5 additions & 1 deletion us/cli/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ def main():
for key in sorted(data.keys()):
val = data[key]

if isinstance(val, (list, tuple)):
if key == "counties":
# counties is a list of County objects, not strings, so it
# can't be joined like the other list attributes
val = "%d counties" % len(val)
elif isinstance(val, (list, tuple)):
val = ", ".join(val)

sys.stdout.write(" %s: %s\n" % (key, val))
Expand Down
14 changes: 14 additions & 0 deletions us/tests/test_us.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytz

import us
from us.cli import states as states_cli
from us.states import County

# attribute
Expand Down Expand Up @@ -246,6 +247,19 @@ def test_dc():
assert us.states.DC not in us.STATES


# cli


def test_cli_lookup(capsys, monkeypatch):
# the counties attribute is a list of County objects, which used to crash
# the "other attributes" loop when it tried to join them as strings
monkeypatch.setattr("sys.argv", ["states", "MD"])
states_cli.main()
out = capsys.readouterr().out
assert "Maryland" in out
assert "counties" in out


# shapefiles


Expand Down