Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
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
11 changes: 4 additions & 7 deletions elex/api/delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,10 @@ def get_report_id(self, reports, key):
"""

for report in reports:
if (
key == 'delSum' and
report.get('title') == 'Delegates / delsum'
) or (
key == 'delSuper' and
report.get('title') == 'Delegates / delsuper'
):
delsum = key == 'delSum' and report.get('title') == 'Delegates / delsum'
delsuper = key == 'delSuper' and report.get('title') == 'Delegates / delsuper'

if delsum or delsuper:
id = report.get('id').rsplit('/', 1)[-1]
return id

Expand Down
9 changes: 3 additions & 6 deletions elex/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,7 @@ def set_new_england_counties(self):
d['precinctsreporting'] += cru.precinctsreporting

try:
d['precinctsreportingpct'] = (
float(d['precinctsreporting']) /
float(d['precinctstotal'])
)
d['precinctsreportingpct'] = (float(d['precinctsreporting']) / float(d['precinctstotal']))

except ZeroDivisionError:
d['precinctsreportingpct'] = 0.0
Expand Down Expand Up @@ -894,7 +891,7 @@ def set_id_field(self):
self.id = self.electiondate

def get(self, path, **params):
"""
r"""
Farms out request to api_request.
Could possibly handle choosing which
parser backend to use -- API-only right now.
Expand Down Expand Up @@ -947,7 +944,7 @@ def get_uniques(self, candidate_reporting_units):
return candidates, ballot_measures

def get_raw_races(self, **params):
"""
r"""
Convenience method for fetching races by election date.
Accepts an AP formatting date string, e.g., YYYY-MM-DD.
Accepts any number of URL params as kwargs.
Expand Down
5 changes: 1 addition & 4 deletions elex/api/trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ def get_report_id(self, reports, key):
organization-specific report ID.
"""
for report in reports:
if (
key == self.office_code and
report.get('title') in [self.api_report_id, self.api_test_report_id]
):
if (key == self.office_code and report.get('title') in [self.api_report_id, self.api_test_report_id]):
id = report.get('id').rsplit('/', 1)[-1]
return id
return None
Expand Down
2 changes: 1 addition & 1 deletion elex/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def write_recording(payload):


def api_request(path, **params):
"""
r"""
Function wrapping Python-requests
for making a request to the AP's
elections API.
Expand Down
5 changes: 1 addition & 4 deletions elex/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,7 @@ def delegates(self):

"""
self.app.log.info('Getting delegate reports')
if (
self.app.pargs.delegate_super_file and
self.app.pargs.delegate_sum_file
):
if (self.app.pargs.delegate_super_file and self.app.pargs.delegate_sum_file):
report = DelegateReport(
delsuper_datafile=self.app.pargs.delegate_super_file,
delsum_datafile=self.app.pargs.delegate_sum_file
Expand Down
2 changes: 1 addition & 1 deletion elex/cli/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def decorated(self):
self.app.log.error('HTTP Error {0} - {1}'.format(e.response.status_code, message))
self.app.log.debug('HTTP Error {0} ({1})'.format(e.response.status_code, e.response.url))
self.app.close(1)
except APAPIKeyException as e:
except APAPIKeyException:
text = 'APAPIKeyError: AP_API_KEY environment variable is not set.'
self.app.log.error(text)
self.app.close(1)
Expand Down
3 changes: 2 additions & 1 deletion elex/cli/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def add_election_hook(app):
app.close(1)
else:
app.election.officeids = app.pargs.officeids
# kept as a comma-delimited string so officeID as a param always appears once in request url (e.g. officeID=P%2CH%2CG)
# kept as a comma-delimited string so officeID as a param always appears once in request url
# (e.g. officeID=P%2CH%2CG)


def cachecontrol_logging_hook(app):
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
universal = 1

[flake8]
max-line-length = 119
max-line-length = 135
ignore = E731

[metadata]
Expand Down
1 change: 0 additions & 1 deletion tests/test_ap_network.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import unittest
import tests

from elex.cli.app import ElexApp
from requests.exceptions import HTTPError
Expand Down
5 changes: 1 addition & 4 deletions tests/test_candidate_reporting_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ def test_candidate_reporting_unit_sums_reportingunit_pct(self):
reporting_unit = self.reporting_units[0]
candidate_reporting_units = self.candidate_reporting_units[0:2]
self.assertEqual(
(
candidate_reporting_units[0].votecount /
float(reporting_unit.votecount)
),
(candidate_reporting_units[0].votecount / float(reporting_unit.votecount)),
0.694266390666554
)

Expand Down
24 changes: 11 additions & 13 deletions tests/test_new_england_reporting_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from elex.api import maps
import tests

is_ct_county = lambda r: r.statepostal == "CT" and r.level == "county"


class TestConnecticutRollups(tests.ElectionResultsTestCase):
"""
Expand All @@ -20,9 +22,7 @@ def test_ct_has_candidates(self):
def test_ct_has_all_counties(self):
ct_counties = set()
raw_counties = [
r for r in self.reporting_units if
r.statepostal == "CT" and
r.level == "county"
r for r in self.reporting_units if is_ct_county(r)
]
for c in raw_counties:
ct_counties.add(c.reportingunitname)
Expand All @@ -33,25 +33,23 @@ def test_ct_has_all_counties(self):

def test_ct_counties_match_townships(self):
ct_counties = [
r for r in self.reporting_units if
r.statepostal == "CT" and
r.level == "county"
r for r in self.reporting_units if is_ct_county(r)
]

for county in ct_counties:
races = set([
r.raceid for r in self.reporting_units if
r.statepostal == "CT" and
r.level == "township" and
r.fipscode == county.fipscode
r.statepostal == "CT" and # noqa: W504
r.level == "township" and # noqa: W504
r.fipscode == county.fipscode # noqa: W504
])
for race in races:
townships = [
r.precinctstotal for r in self.reporting_units if
r.statepostal == "CT" and
r.level == "township" and
r.fipscode == county.fipscode and
r.raceid == race
r.statepostal == "CT" and # noqa: W504
r.level == "township" and # noqa: W504
r.fipscode == county.fipscode and # noqa: W504
r.raceid == race # noqa: W504
]
self.assertEqual(county.precinctstotal, sum(townships))

Expand Down
5 changes: 1 addition & 4 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ def test_number_of_counties(self):
According to bug #236, we should be 1 county short.
"""
mass_results = [
r for r in self.results if
r.raceid == '24547' and
r.level == 'county' and
r.last == 'Trump'
r for r in self.results if r.raceid == '24547' and r.level == 'county' and r.last == 'Trump'
]
self.assertEqual(len(mass_results), len(maps.FIPS_TO_STATE['MA']))

Expand Down