diff --git a/us/cli/states.py b/us/cli/states.py index ae79819..c075ad4 100644 --- a/us/cli/states.py +++ b/us/cli/states.py @@ -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)) diff --git a/us/tests/test_us.py b/us/tests/test_us.py index b98482f..4c1d4d3 100644 --- a/us/tests/test_us.py +++ b/us/tests/test_us.py @@ -6,6 +6,7 @@ import pytz import us +from us.cli import states as states_cli from us.states import County # attribute @@ -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