Skip to content

Commit

Permalink
add cli tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fitnr committed Jan 8, 2016
1 parent 8de3668 commit 8480549
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/__init__.py
Expand Up @@ -9,3 +9,4 @@
# Copyright (c) 2016, fitnr <fitnr@fakeisthenewreal>

from . import base
from . import test_cli
6 changes: 3 additions & 3 deletions tests/base.py
Expand Up @@ -36,8 +36,8 @@ def testGetCounty(self):
assert self.af.get_state_fips('new york') == '36'

def testEmpty(self):
assert self.af.get_county_fips('foo') is None
assert self.af.get_county_fips('foo', state_name='New York') is None
assert self.af.get_county_fips('foo', 'bar') is None
assert self.af.get_county_fips('foo', state='New York') is None

def testCountyRow(self):
new = self.af.add_county_fips(self.row, county_field='county', state_field='state')
Expand All @@ -51,7 +51,7 @@ def testCountyRow(self):
assert new['fips'] == '36047'

def testCountyRowStateName(self):
new = self.af.add_county_fips(self.row, county_field='county', state_name='New York')
new = self.af.add_county_fips(self.row, county_field='county', state='New York')
assert new['fips'] == '36047'
assert new['foo'] == 'bar'

Expand Down
57 changes: 57 additions & 0 deletions tests/test_cli.py
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This file is part of addfips.
# http://github.com/fitnr/addfips

# Licensed under the GPL-v3.0 license:
# http://opensource.org/licenses/GPL-3.0
# Copyright (c) 2016, fitnr <fitnr@fakeisthenewreal>

import unittest
import subprocess
import csv
try:
import StringIO as io
except ImportError:
import io

from pkg_resources import resource_filename


class testcli(unittest.TestCase):
def setUp(self):
self.states = resource_filename('addfips', 'data/states.csv')
self.counties = resource_filename('addfips', 'data/counties_2015.csv')

def testStateCli(self):
args = ['addfips', self.states, '-s', 'name']
p = subprocess.Popen(args, stdout=subprocess.PIPE)

out, err = p.communicate()

assert err is None

f = io.StringIO(out.decode('utf8'))

reader = csv.DictReader(f)
row = next(reader)

assert row['name'] == 'Alabama'
assert row['fips'] == '01'

def testCountyCli(self):
args = ['addfips', self.counties, '-s', 'statefp', '-c', 'name']
p = subprocess.Popen(args, stdout=subprocess.PIPE)

out, err = p.communicate()

assert err is None

f = io.StringIO(out.decode('utf-8'))

reader = csv.DictReader(f)
row = next(reader)

assert row['name'] == 'Autauga County'
assert row['fips'] == '01001'

0 comments on commit 8480549

Please sign in to comment.