Permalink
Browse files

Candidate object now includes a is_incumbent boolean

  • Loading branch information...
1 parent 02fbe71 commit 928b7815bd3446232787f369f07f78cd8e141806 @palewire palewire committed May 31, 2012
Showing with 8 additions and 3 deletions.
  1. +5 −1 elections/ap.py
  2. +1 −1 setup.py
  3. +2 −1 tests.py
View
@@ -618,6 +618,9 @@ def _get_flat_results(self, ftp=None):
candidate.is_winner = cand['is_winner'] == 'X'
candidate.is_runoff = cand['is_winner'] == 'R'
+ # Set whether the candidate is an incumbent
+ candidate.is_incumbent = cand['incumbent'] == '1'
+
# Create the Result object, which is specific to the
# reporting unit in this row of the flatfile.
result = Result(
@@ -1077,7 +1080,7 @@ def __init__(self, first_name=None, middle_name=None, last_name=None,
abbrev_name=None, suffix=None, use_suffix=False,
ap_natl_number=None, ap_polra_number=None, ap_race_number=None,
party=None, ap_pol_number=None, is_winner=None,
- is_runoff=None, delegates=None):
+ is_runoff=None, delegates=None, is_incumbent=None):
self.first_name = first_name
self.middle_name = middle_name
self.last_name = last_name
@@ -1092,6 +1095,7 @@ def __init__(self, first_name=None, middle_name=None, last_name=None,
self.is_winner = is_winner
self.is_runoff = is_runoff
self.delegates = delegates
+ self.is_incumbent = is_incumbent
def __unicode__(self):
return unicode(self.name)
View
@@ -71,7 +71,7 @@ def fullsplit(path, result=None):
file_info[0] = '\\PURELIB\\%s' % file_info[0]
setup(name='python-elections',
- version='0.34',
+ version='0.35',
description='A Python wrapper for the Associated Press\'s U.S. election data service.',
author='The Los Angeles Times Data Desk',
author_email='datadesk@latimes.com',
View
@@ -26,7 +26,7 @@ class APTest(BaseTest):
def test_badlogin(self):
client = AP("foo", "bar")
- self.assertRaises(BadCredentialsError, client.get_state, "IA")
+ self.assertRaises(BadCredentialsError, client.get_state, "CA")
def test_badstate(self):
self.assertRaises(FileDoesNotExistError, self.client.get_state, "XYZ")
@@ -156,6 +156,7 @@ def test_getstate(self):
self.assertTrue(isinstance(cand.party, basestring))
self.assertTrue(isinstance(cand.is_winner, bool))
self.assertTrue(isinstance(cand.is_runoff, bool))
+ self.assertTrue(isinstance(cand.is_incumbent, bool))
self.assertTrue(isinstance(cand.delegates, int))
self.assertTrue(isinstance(cand.name, basestring))

0 comments on commit 928b781

Please sign in to comment.