From 84805497ab9f94e28b2b6f21565beabf96667788 Mon Sep 17 00:00:00 2001 From: fitnr Date: Thu, 7 Jan 2016 20:24:00 -0500 Subject: [PATCH] add cli tests --- tests/__init__.py | 1 + tests/base.py | 6 ++--- tests/test_cli.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 tests/test_cli.py diff --git a/tests/__init__.py b/tests/__init__.py index afb9d63..3a44b27 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -9,3 +9,4 @@ # Copyright (c) 2016, fitnr from . import base +from . import test_cli diff --git a/tests/base.py b/tests/base.py index d5c4f2c..ca46d5e 100644 --- a/tests/base.py +++ b/tests/base.py @@ -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') @@ -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' diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..7cb733d --- /dev/null +++ b/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 + +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'