<s> import datetime <EOL> import re <EOL> from unittest import skipUnless , TestCase <EOL> from openelex . lib . text import ocd_type_id <EOL> from openelex . tests import cache_file_exists <EOL> from openelex . us . ia . load import ( ExcelPrecinctResultLoader , <EOL> ExcelPrecinctPre2010ResultLoader , ExcelPrecinct2010PrimaryResultLoader , <EOL> ExcelPrecinct2010GeneralResultLoader , <EOL> ExcelPrecinct2010GeneralAudubonResultLoader , <EOL> ExcelPrecinct2010GeneralClintonResultLoader , <EOL> ExcelPrecinct2010GeneralGrundyResultLoader , <EOL> ExcelPrecinct2010GeneralHenryResultLoader , <EOL> ExcelPrecinct2010GeneralJohnsonResultLoader , <EOL> ExcelPrecinct2010GeneralLouisaResultLoader , <EOL> ExcelPrecinct2010GeneralPoweshiekResultLoader , ExcelPrecinct2012ResultLoader , <EOL> ExcelPrecinct2013ResultLoader , <EOL> ExcelPrecinct2014ResultLoader , LoadResults , PreprocessedResultsLoader ) <EOL> CACHED_FILE_MISSING_MSG = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> class LoaderPrepMixin ( object ) : <EOL> def _get_mapping ( self , filename ) : <EOL> return self . loader . datasource . mapping_for_file ( filename ) <EOL> def _prep_loader_attrs ( self , mapping ) : <EOL> self . loader . source = mapping [ '<STR_LIT>' ] <EOL> self . loader . election_id = mapping [ '<STR_LIT>' ] <EOL> self . loader . timestamp = datetime . datetime . now ( ) <EOL> class TestLoadResults ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = LoadResults ( ) <EOL> def test_get_loader ( self ) : <EOL> mapping = { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> loader = self . loader . _get_loader ( mapping ) <EOL> self . assertEqual ( loader . __class__ , PreprocessedResultsLoader ) <EOL> mapping = { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> loader = self . loader . _get_loader ( mapping ) <EOL> self . assertEqual ( loader . __class__ , ExcelPrecinctPre2010ResultLoader ) <EOL> mapping = { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> loader = self . loader . _get_loader ( mapping ) <EOL> self . assertEqual ( loader . __class__ , ExcelPrecinct2010PrimaryResultLoader ) <EOL> mapping = { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> loader = self . loader . _get_loader ( mapping ) <EOL> self . assertEqual ( loader . __class__ , ExcelPrecinct2010GeneralResultLoader ) <EOL> mapping = { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> loader = self . loader . _get_loader ( mapping ) <EOL> self . assertEqual ( loader . __class__ , ExcelPrecinct2012ResultLoader ) <EOL> mapping = { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> loader = self . loader . _get_loader ( mapping ) <EOL> self . assertEqual ( loader . __class__ , ExcelPrecinct2012ResultLoader ) <EOL> mapping = { <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' , <EOL> '<STR_LIT>' : u'<STR_LIT>' <EOL> } <EOL> loader = self . loader . _get_loader ( mapping ) <EOL> self . assertEqual ( loader . __class__ , ExcelPrecinct2014ResultLoader ) <EOL> class TestExcelPrecinctResultLoader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinctResultLoader ( ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_rows ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> rows = list ( self . loader . _rows ( ) ) <EOL> self . assertEqual ( len ( rows ) , <NUM_LIT> ) <EOL> class TestExcelPrecinctPre2010ResultLoader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinctPre2010ResultLoader ( ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results_2006 ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> ag_results = [ r for r in self . loader . _results ( mapping ) <EOL> if r . office == "<STR_LIT>" ] <EOL> self . assertEqual ( len ( ag_results ) , <NUM_LIT> ) <EOL> result = next ( r for r in ag_results <EOL> if r . reporting_level == '<STR_LIT>' ) <EOL> self . assertEqual ( result . source , mapping [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result . election_id , mapping [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result . state , "<STR_LIT>" ) <EOL> self . assertEqual ( result . election_type , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , None ) <EOL> self . assertEqual ( result . party , None ) <EOL> self . assertEqual ( result . jurisdiction , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> county_ag_results = [ r for r in ag_results <EOL> if r . reporting_level == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( county_ag_results ) , <NUM_LIT:15> ) <EOL> result = county_ag_results [ <NUM_LIT:0> ] <EOL> result = next ( r for r in county_ag_results <EOL> if r . votes_type == None and <EOL> r . full_name == "<STR_LIT>" ) <EOL> self . assertEqual ( result . jurisdiction , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> result = next ( r for r in county_ag_results <EOL> if r . votes_type == "<STR_LIT>" and <EOL> r . full_name == "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> result = next ( r for r in county_ag_results <EOL> if r . votes_type == "<STR_LIT>" and <EOL> r . full_name == "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT:0> ) <EOL> result = next ( r for r in self . loader . _results ( mapping ) <EOL> if r . office == "<STR_LIT>" ) <EOL> self . assertTrue ( re . match ( r'<STR_LIT>' , result . district ) ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results_2008 ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> senate_results = [ r for r in self . loader . _results ( mapping ) <EOL> if r . office == "<STR_LIT>" ] <EOL> self . assertEqual ( len ( senate_results ) , <NUM_LIT> ) <EOL> result = next ( r for r in senate_results <EOL> if r . reporting_level == '<STR_LIT>' ) <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . jurisdiction , "<STR_LIT>" ) <EOL> def test_parse_office ( self ) : <EOL> office_district = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT:5>" ) , <EOL> ] <EOL> for office in office_district : <EOL> try : <EOL> office_in , expected_office , expected_district = office <EOL> except ValueError : <EOL> office_in = office <EOL> expected_office = office <EOL> expected_district = None <EOL> office_out , district = self . loader . _parse_office ( office_in ) <EOL> self . assertEqual ( office_out , expected_office ) <EOL> self . assertEqual ( district , expected_district ) <EOL> def test_parse_result_row ( self ) : <EOL> candidates = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> row = [ <EOL> "<STR_LIT>" , <EOL> <NUM_LIT> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:100> , <EOL> <NUM_LIT:5> , <EOL> <NUM_LIT> , <EOL> ] <EOL> results = self . loader . _parse_result_row ( row , candidates , <EOL> county = '<STR_LIT>' , county_ocd_id = '<STR_LIT>' ) <EOL> jurisdiction = row [ <NUM_LIT:0> ] <EOL> result_i = <NUM_LIT:0> <EOL> i = <NUM_LIT:0> <EOL> while i < len ( candidates ) : <EOL> candidate = candidates [ i ] <EOL> if candidate != "<STR_LIT>" : <EOL> result = results [ result_i ] <EOL> votes = row [ i + <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , candidate ) <EOL> self . assertEqual ( result . votes , votes ) <EOL> self . assertEqual ( result . jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> assert result . ocd_id . endswith ( ocd_type_id ( jurisdiction ) ) <EOL> result_i += <NUM_LIT:1> <EOL> i += <NUM_LIT:1> <EOL> self . assertEqual ( len ( results ) , result_i ) <EOL> def test_parse_result_row_pseudo_candidates ( self ) : <EOL> candidates = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> row = [ <EOL> "<STR_LIT>" , <EOL> <NUM_LIT> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:100> , <EOL> <NUM_LIT:5> , <EOL> <NUM_LIT> , <EOL> ] <EOL> results = self . loader . _parse_result_row ( row , candidates , <EOL> county = '<STR_LIT>' , county_ocd_id = '<STR_LIT>' ) <EOL> result = next ( r for r in results if r . full_name == "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> result = next ( r for r in results if r . full_name == "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> def test_parse_result_row_absentee ( self ) : <EOL> candidates = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> row = [ <EOL> '<STR_LIT>' , <EOL> <NUM_LIT> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT:7> , <EOL> <NUM_LIT> , <EOL> ] <EOL> county = '<STR_LIT>' <EOL> county_ocd_id = '<STR_LIT>' <EOL> results = self . loader . _parse_result_row ( row , candidates , <EOL> county = county , county_ocd_id = county_ocd_id ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . jurisdiction , county ) <EOL> self . assertEqual ( result . ocd_id , county_ocd_id ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> def test_parse_result_row_provisional ( self ) : <EOL> candidates = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> row = [ <EOL> '<STR_LIT>' , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> ] <EOL> county = '<STR_LIT>' <EOL> county_ocd_id = '<STR_LIT>' <EOL> results = self . loader . _parse_result_row ( row , candidates , <EOL> county = county , county_ocd_id = county_ocd_id ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . jurisdiction , county ) <EOL> self . assertEqual ( result . ocd_id , county_ocd_id ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> def test_votes_type ( self ) : <EOL> test_vals = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ) <EOL> for candidate , jurisdiction , expected in test_vals : <EOL> votes_type = self . loader . _votes_type ( jurisdiction ) <EOL> self . assertEqual ( votes_type , expected ) <EOL> class TestExcelPrecinct2010PrimaryResultLoader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010PrimaryResultLoader ( ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> us_rep_dist_5_rep_results = [ r for r in results <EOL> if ( r . office == "<STR_LIT>" and <EOL> r . district == "<STR_LIT:5>" and <EOL> r . primary_party == "<STR_LIT>" ) ] <EOL> self . assertEqual ( len ( us_rep_dist_5_rep_results ) , <NUM_LIT> ) <EOL> result = us_rep_dist_5_rep_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . source , mapping [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result . election_id , mapping [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result . state , "<STR_LIT>" ) <EOL> self . assertEqual ( result . election_type , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , "<STR_LIT:5>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . jurisdiction , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> def test_parse_office_party ( self ) : <EOL> vals = ( <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:5>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> for raw , office_expected , district_expected , party_expected in vals : <EOL> office , district , party = self . loader . _parse_office_party ( raw ) <EOL> self . assertEqual ( office , office_expected ) <EOL> self . assertEqual ( district , district_expected ) <EOL> self . assertEqual ( party , party_expected ) <EOL> def test_parse_candidates ( self ) : <EOL> row = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> candidates = self . loader . _parse_candidates ( row ) <EOL> self . assertEqual ( candidates [ <NUM_LIT:0> ] , '<STR_LIT>' ) <EOL> self . assertEqual ( candidates [ - <NUM_LIT:1> ] , '<STR_LIT>' ) <EOL> def test_parse_result_row ( self ) : <EOL> candidates = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> row = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> <NUM_LIT:30> , <EOL> <NUM_LIT:6> , <EOL> <NUM_LIT:4> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT> , <EOL> '<STR_LIT:Y>' , <EOL> ] <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = "<STR_LIT>" <EOL> results = self . loader . _parse_result_row ( row , candidates , county , <EOL> county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . jurisdiction , row [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( result . full_name , candidates [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:3> ] ) <EOL> def test_parse_result_row_grand_totals ( self ) : <EOL> candidates = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> row = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:8> , <EOL> <NUM_LIT> , <EOL> '<STR_LIT>' , <EOL> ] <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = "<STR_LIT>" <EOL> results = self . loader . _parse_result_row ( row , candidates , county , <EOL> county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . jurisdiction , "<STR_LIT>" ) <EOL> self . assertEqual ( result . full_name , candidates [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:3> ] ) <EOL> def test_parse_result_row_grand_absentee ( self ) : <EOL> candidates = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> row = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> <NUM_LIT:16> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:8> , <EOL> <NUM_LIT:0> , <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT:1> , <EOL> <NUM_LIT> , <EOL> '<STR_LIT:Y>' , <EOL> ] <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = "<STR_LIT>" <EOL> results = self . loader . _parse_result_row ( row , candidates , county , <EOL> county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . jurisdiction , "<STR_LIT>" ) <EOL> self . assertEqual ( result . full_name , candidates [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> def test_votes_type ( self ) : <EOL> test_vals = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ) <EOL> for candidate , jurisdiction , expected in test_vals : <EOL> votes_type = self . loader . _votes_type ( jurisdiction ) <EOL> self . assertEqual ( votes_type , expected ) <EOL> class TestExcelPrecinct2010GeneralResultLoader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralResultLoader ( ) <EOL> def test_parse_result_row_skip ( self ) : <EOL> rows = [ <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <NUM_LIT:1.0> ] , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <NUM_LIT> ] , <EOL> [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <NUM_LIT> ] <EOL> ] <EOL> county = None <EOL> county_ocd_id = None <EOL> for row in rows : <EOL> self . assertEqual ( self . loader . _parse_result_row ( row , county , <EOL> county_ocd_id ) , None ) <EOL> def test_parse_result_row ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <NUM_LIT> ] <EOL> expected_ocd_id = county_ocd_id + '<STR_LIT:/>' + ocd_type_id ( row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> results = self . loader . _parse_result_row ( row , county , county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:1> ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . jurisdiction , row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> self . assertEqual ( result . ocd_id , expected_ocd_id ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . office , row [ <NUM_LIT:1> ] . strip ( ) ) <EOL> self . assertEqual ( result . full_name , row [ <NUM_LIT:2> ] . strip ( ) ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> def test_parse_result_row_multiple ( self ) : <EOL> """<STR_LIT>""" <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> expected_ocd_id = county_ocd_id + '<STR_LIT:/>' + ocd_type_id ( row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> results = self . loader . _parse_result_row ( row , county , county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:1> ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . jurisdiction , row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> self . assertEqual ( result . ocd_id , expected_ocd_id ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . office , row [ <NUM_LIT:1> ] . strip ( ) ) <EOL> self . assertEqual ( result . full_name , row [ <NUM_LIT:2> ] . strip ( ) ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , row [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , row [ <NUM_LIT:4> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:5> ] ) <EOL> class TestExcelPrecinct2010GeneralAudubonResultLoader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralAudubonResultLoader ( ) <EOL> def test_clean_jurisdiction_cell ( self ) : <EOL> test_data = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> for val , expected in test_data : <EOL> self . assertEqual ( self . loader . _clean_jurisdiction_cell ( val ) , <EOL> expected ) <EOL> def test_parse_jurisdictions ( self ) : <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> expected = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> jurisdictions = self . loader . _parse_jurisdictions ( row ) <EOL> self . assertEqual ( jurisdictions , expected ) <EOL> def test_parse_office ( self ) : <EOL> test_data = [ <EOL> ( '<STR_LIT>' , "<STR_LIT>" , None ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" , "<STR_LIT:5>" ) , <EOL> ( '<STR_LIT>' , None , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] <EOL> for cell , expected_office , expected_district in test_data : <EOL> office , district = self . loader . _parse_office ( cell ) <EOL> self . assertEqual ( office , expected_office ) <EOL> self . assertEqual ( district , expected_district ) <EOL> def test_parse_result_row ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , '<STR_LIT>' ] <EOL> jurisdictions = [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> ] <EOL> results = self . loader . _parse_result_row ( row , jurisdictions , county , <EOL> county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( jurisdictions ) ) <EOL> for result , votes , jurisdiction in zip ( results , row [ <NUM_LIT:2> : - <NUM_LIT:1> ] , jurisdictions ) : <EOL> reporting_level = '<STR_LIT>' <EOL> votes_type = None <EOL> clean_jurisdiction = jurisdiction <EOL> if jurisdiction in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> clean_jurisdiction = county <EOL> reporting_level = '<STR_LIT>' <EOL> if "<STR_LIT>" in jurisdiction : <EOL> votes_type = '<STR_LIT>' <EOL> elif "<STR_LIT>" in jurisdiction : <EOL> votes_type = None <EOL> else : <EOL> votes_type = '<STR_LIT>' <EOL> self . assertEqual ( result . full_name , row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> self . assertEqual ( result . party , row [ <NUM_LIT:1> ] . strip ( ) ) <EOL> self . assertEqual ( result . jurisdiction , clean_jurisdiction ) <EOL> self . assertEqual ( result . reporting_level , reporting_level ) <EOL> self . assertEqual ( result . votes , votes ) <EOL> self . assertEqual ( result . votes_type , votes_type ) <EOL> class TestExcelPrecinct2010GeneralClintonResultLoader ( LoaderPrepMixin , <EOL> TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralClintonResultLoader ( ) <EOL> def test_parse_office ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district = self . loader . _parse_office ( row ) <EOL> self . assertEqual ( office , '<STR_LIT>' ) <EOL> self . assertEqual ( district , None ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district = self . loader . _parse_office ( row ) <EOL> self . assertEqual ( office , '<STR_LIT>' ) <EOL> self . assertEqual ( district , '<STR_LIT:1>' ) <EOL> def test_parse_result_row ( self ) : <EOL> row = [ u'<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:1> ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , row [ <NUM_LIT:3> ] ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , row [ <NUM_LIT:4> ] ) <EOL> def test_parse_candidate ( self ) : <EOL> test_data = [ <EOL> ( '<STR_LIT>' , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" , None ) , <EOL> ( '<STR_LIT>' , "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] <EOL> for cell , expected_candidate , expected_party in test_data : <EOL> candidate , party = self . loader . _parse_candidate ( cell ) <EOL> self . assertEqual ( candidate , expected_candidate ) <EOL> self . assertEqual ( party , expected_party ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> filtered_results = [ r for r in results <EOL> if r . office == '<STR_LIT>' and <EOL> r . district == '<STR_LIT>' and <EOL> r . jurisdiction == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( filtered_results ) , <NUM_LIT:5> ) <EOL> result = filtered_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> result = filtered_results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , None ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , <NUM_LIT:11> ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT:7> ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT:4> ) <EOL> class TestExcelPrecinct2010GeneralGrundyResultLoader ( LoaderPrepMixin , <EOL> TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralGrundyResultLoader ( ) <EOL> def test_parse_office ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district = self . loader . _parse_office ( row ) <EOL> self . assertEqual ( office , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( district , None ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district = self . loader . _parse_office ( row ) <EOL> self . assertEqual ( office , '<STR_LIT>' ) <EOL> self . assertEqual ( district , '<STR_LIT:3>' ) <EOL> def test_parse_candidate ( self ) : <EOL> test_data = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ] <EOL> for cell , expected_candidate , expected_writein in test_data : <EOL> candidate , writein = self . loader . _parse_candidate ( cell ) <EOL> self . assertEqual ( candidate , expected_candidate ) <EOL> self . assertEqual ( writein , expected_writein ) <EOL> def test_parse_result_row ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> jurisdictions = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> row = [ u'<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row , jurisdictions , county , <EOL> county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( jurisdictions ) ) <EOL> for result in results : <EOL> self . assertEqual ( result . full_name , row [ <NUM_LIT:0> ] ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . jurisdiction , jurisdictions [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> result = results [ - <NUM_LIT:2> ] <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . jurisdiction , county ) <EOL> self . assertEqual ( result . votes , row [ - <NUM_LIT:2> ] ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> result = results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . jurisdiction , county ) <EOL> self . assertEqual ( result . votes , row [ - <NUM_LIT:1> ] ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> sec_of_state_results = [ r for r in results <EOL> if r . office == "<STR_LIT>" ] <EOL> self . assertEqual ( len ( sec_of_state_results ) , <NUM_LIT> ) <EOL> county_results = [ r for r in sec_of_state_results <EOL> if r . reporting_level == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( county_results ) , <NUM_LIT:20> ) <EOL> result = sec_of_state_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> result = sec_of_state_results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> class TestExcelPrecinct2010GeneralHenryResultLoader ( LoaderPrepMixin , <EOL> TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralHenryResultLoader ( ) <EOL> def test_parse_result_row ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> jurisdictions = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> row = [ u'<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , '<STR_LIT>' ] <EOL> results = self . loader . _parse_result_row ( row , jurisdictions , county , county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( jurisdictions ) ) <EOL> for result in results : <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . jurisdiction , county ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> result = results [ <NUM_LIT:1> ] <EOL> self . assertEqual ( result . jurisdiction , jurisdictions [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> result = results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . jurisdiction , county ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , row [ - <NUM_LIT:2> ] ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> state_rep_results = [ r for r in results <EOL> if ( r . office == "<STR_LIT>" and <EOL> r . district == "<STR_LIT>" ) ] <EOL> self . assertEqual ( len ( state_rep_results ) , <NUM_LIT> ) <EOL> precinct_results = [ r for r in state_rep_results <EOL> if r . reporting_level == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( precinct_results ) , <NUM_LIT> ) <EOL> county_results = [ r for r in state_rep_results <EOL> if r . reporting_level == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( county_results ) , <NUM_LIT:10> ) <EOL> result = state_rep_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> self . assertEqual ( result . jurisdiction , "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> result = state_rep_results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , None ) <EOL> self . assertEqual ( result . votes , <NUM_LIT:0> ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> self . assertEqual ( result . jurisdiction , "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> class TestExcelPrecinct2010GeneralJohnsonResultLoader ( LoaderPrepMixin , <EOL> TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralJohnsonResultLoader ( ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> sr_dist_29_results = [ r for r in results <EOL> if r . office == "<STR_LIT>" <EOL> and r . district == "<STR_LIT>" <EOL> and r . jurisdiction == "<STR_LIT>" ] <EOL> self . assertEqual ( len ( sr_dist_29_results ) , <NUM_LIT:6> ) <EOL> result = sr_dist_29_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT> ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT:20> ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> result = sr_dist_29_results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , None ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT:7> ) <EOL> self . assertEqual ( result . vote_breakdowns [ '<STR_LIT>' ] , <NUM_LIT:6> ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> class TestExcelPrecinct2010GeneralLouisaResultLoader ( LoaderPrepMixin , <EOL> TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralLouisaResultLoader ( ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> wapello_city_results = [ r for r in results <EOL> if r . jurisdiction == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( wapello_city_results ) , <NUM_LIT> * <NUM_LIT:2> ) <EOL> result = wapello_city_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . office , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , None ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> result = wapello_city_results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , None ) <EOL> self . assertEqual ( result . office , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> county_results = [ r for r in results <EOL> if r . reporting_level == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( county_results ) , <NUM_LIT> ) <EOL> def test_parse_office_row ( self ) : <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> offices = self . loader . _parse_office_row ( row ) <EOL> office , district = offices [ <NUM_LIT:0> ] <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , None ) <EOL> office , district = offices [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , "<STR_LIT>" ) <EOL> def test_parse_candidate ( self ) : <EOL> test_data = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ] <EOL> for cell , expected_candidate , expected_party in test_data : <EOL> candidate , party = self . loader . _parse_candidate ( cell ) <EOL> self . assertEqual ( candidate , expected_candidate ) <EOL> self . assertEqual ( party , expected_party ) <EOL> class TestExcelPrecinct2010GeneralPoweshiekResultLoader ( LoaderPrepMixin , <EOL> TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2010GeneralPoweshiekResultLoader ( ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> montezuma_abs_results = [ r for r in results <EOL> if r . jurisdiction == '<STR_LIT>' and <EOL> r . votes_type == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( montezuma_abs_results ) , <NUM_LIT> ) <EOL> result = montezuma_abs_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . office , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , None ) <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . write_in , None ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> result = montezuma_abs_results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . office , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , "<STR_LIT>" ) <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , None ) <EOL> self . assertEqual ( result . write_in , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT:0> ) <EOL> def test_parse_office_row ( self ) : <EOL> row0 = [ u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT:U+0020>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:1.0> , '<STR_LIT>' , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> row1 = [ '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> offices = self . loader . _parse_office_row ( row0 , row1 ) <EOL> office , district = offices [ <NUM_LIT:0> ] <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , None ) <EOL> office , district = offices [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , "<STR_LIT>" ) <EOL> def test_parse_candidates_row ( self ) : <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> candidates = self . loader . _parse_candidates_row ( row ) <EOL> candidate , party = candidates [ <NUM_LIT:0> ] <EOL> self . assertEqual ( candidate , "<STR_LIT>" ) <EOL> self . assertEqual ( party , "<STR_LIT>" ) <EOL> candidate , party = candidates [ <NUM_LIT> ] <EOL> self . assertEqual ( candidate , "<STR_LIT>" ) <EOL> self . assertEqual ( party , "<STR_LIT>" ) <EOL> class TestExcelPrecinct2012Loader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2012ResultLoader ( ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results_primary ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> state_senate_district_10_rep_results = [ r for r in results <EOL> if ( r . office == "<STR_LIT>" and <EOL> r . district == "<STR_LIT>" and <EOL> r . primary_party == "<STR_LIT:R>" ) ] <EOL> self . assertEqual ( len ( state_senate_district_10_rep_results ) , <NUM_LIT> ) <EOL> result = next ( r for r in state_senate_district_10_rep_results <EOL> if r . jurisdiction == "<STR_LIT>" ) <EOL> self . assertEqual ( result . source , mapping [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result . election_id , mapping [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( result . state , "<STR_LIT>" ) <EOL> self . assertEqual ( result . election_type , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT:R>" ) <EOL> self . assertEqual ( result . jurisdiction , "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> @ skipUnless ( cache_file_exists ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , CACHED_FILE_MISSING_MSG ) <EOL> def test_results_general ( self ) : <EOL> filename = '<STR_LIT>' <EOL> mapping = self . _get_mapping ( filename ) <EOL> self . _prep_loader_attrs ( mapping ) <EOL> results = self . loader . _results ( mapping ) <EOL> state_rep_district_20_results = [ r for r in results <EOL> if ( r . office == "<STR_LIT>" and r . district == "<STR_LIT>" ) ] <EOL> precinct_2ne_results = [ r for r in state_rep_district_20_results <EOL> if r . jurisdiction == "<STR_LIT>" ] <EOL> self . assertEqual ( len ( precinct_2ne_results ) , <NUM_LIT> ) <EOL> absentee_results = [ r for r in state_rep_district_20_results if r . votes_type == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( absentee_results ) , <NUM_LIT> ) <EOL> county_results = [ r for r in state_rep_district_20_results if r . reporting_level == '<STR_LIT>' ] <EOL> self . assertEqual ( len ( county_results ) , <NUM_LIT> ) <EOL> result = state_rep_district_20_results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> self . assertEqual ( result . primary_party , None ) <EOL> self . assertEqual ( result . state , "<STR_LIT>" ) <EOL> self . assertEqual ( result . election_type , '<STR_LIT>' ) <EOL> self . assertEqual ( result . office , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , '<STR_LIT>' ) <EOL> result = state_rep_district_20_results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , "<STR_LIT>" ) <EOL> self . assertEqual ( result . party , None ) <EOL> self . assertEqual ( result . primary_party , None ) <EOL> self . assertEqual ( result . state , "<STR_LIT>" ) <EOL> self . assertEqual ( result . election_type , '<STR_LIT>' ) <EOL> self . assertEqual ( result . office , "<STR_LIT>" ) <EOL> self . assertEqual ( result . district , "<STR_LIT>" ) <EOL> self . assertEqual ( result . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> self . assertEqual ( result . votes_type , None ) <EOL> def test_page_header_row ( self ) : <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ; <EOL> self . assertEqual ( self . loader . _page_header_row ( row ) , True ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _page_header_row ( row ) , True ) <EOL> def test_empty_row ( self ) : <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _empty_row ( row ) , False ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _empty_row ( row ) , True ) <EOL> def test_parse_office_row ( self ) : <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district , primary_party = self . loader . _parse_office_row ( row ) <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , "<STR_LIT:3>" ) <EOL> self . assertEqual ( primary_party , "<STR_LIT:R>" ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district , primary_party = self . loader . _parse_office_row ( row ) <EOL> self . assertEqual ( office , None ) <EOL> self . assertEqual ( district , None ) <EOL> self . assertEqual ( primary_party , None ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' ] <EOL> office , district , primary_party = self . loader . _parse_office_row ( row ) <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , None ) <EOL> self . assertEqual ( primary_party , None ) <EOL> def test_parse_candidates_row ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> candidates = self . loader . _parse_candidates_row ( row ) <EOL> self . assertEqual ( candidates , None ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' ] <EOL> candidates = self . loader . _parse_candidates_row ( row ) <EOL> self . assertEqual ( len ( candidates ) , <NUM_LIT:5> ) <EOL> candidate , party = candidates [ <NUM_LIT:0> ] <EOL> self . assertEqual ( candidate , "<STR_LIT>" ) <EOL> self . assertEqual ( party , None ) <EOL> candidate , party = candidates [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( candidate , "<STR_LIT>" ) <EOL> self . assertEqual ( party , None ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> candidates = self . loader . _parse_candidates_row ( row ) <EOL> self . assertEqual ( len ( candidates ) , <NUM_LIT:5> ) <EOL> candidate , party = candidates [ <NUM_LIT:0> ] <EOL> self . assertEqual ( candidate , "<STR_LIT>" ) <EOL> self . assertEqual ( party , "<STR_LIT>" ) <EOL> candidate , party = candidates [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( candidate , "<STR_LIT>" ) <EOL> self . assertEqual ( party , None ) <EOL> def test_parse_jurisdiction ( self ) : <EOL> prev_reporting_level = None <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' ] <EOL> jurisdiction , level = self . loader . _parse_jurisdiction ( row , <EOL> prev_reporting_level ) <EOL> self . assertEqual ( jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( level , '<STR_LIT>' ) <EOL> prev_reporting_level = '<STR_LIT>' <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' ] <EOL> jurisdiction , level = self . loader . _parse_jurisdiction ( row , <EOL> prev_reporting_level ) <EOL> self . assertEqual ( jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( level , '<STR_LIT>' ) <EOL> prev_reporting_level = '<STR_LIT>' <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' ] <EOL> jurisdiction , level = self . loader . _parse_jurisdiction ( row , <EOL> prev_reporting_level ) <EOL> self . assertEqual ( jurisdiction , row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> self . assertEqual ( level , '<STR_LIT>' ) <EOL> prev_reporting_level = '<STR_LIT>' <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> jurisdiction , level = self . loader . _parse_jurisdiction ( row , <EOL> prev_reporting_level ) <EOL> self . assertEqual ( jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( level , '<STR_LIT>' ) <EOL> prev_reporting_level = '<STR_LIT>' <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> jurisdiction , level = self . loader . _parse_jurisdiction ( row , <EOL> prev_reporting_level ) <EOL> self . assertEqual ( jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( level , '<STR_LIT>' ) <EOL> prev_reporting_level = '<STR_LIT>' <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> jurisdiction , level = self . loader . _parse_jurisdiction ( row , <EOL> prev_reporting_level ) <EOL> self . assertEqual ( jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( level , '<STR_LIT>' ) <EOL> prev_reporting_level = '<STR_LIT>' <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> jurisdiction , level = self . loader . _parse_jurisdiction ( row , <EOL> prev_reporting_level ) <EOL> self . assertEqual ( jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( level , '<STR_LIT>' ) <EOL> def test_parse_result_row_primary ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> common_kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> candidates = [ <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) <EOL> ] <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row , candidates , county , <EOL> county_ocd_id , ** common_kwargs ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , candidates [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:5> ] ) <EOL> self . assertEqual ( result . reporting_level , "<STR_LIT>" ) <EOL> self . assertEqual ( result . jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> result = results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , candidates [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ - <NUM_LIT:1> ] ) <EOL> def test_fix_row ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT> ] <EOL> self . assertEqual ( self . loader . _fix_row ( row ) , row ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0.0> , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT:0.0> , '<STR_LIT>' , <NUM_LIT:0.0> , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ] <EOL> fixed = row [ <NUM_LIT:0> : <NUM_LIT> ] + row [ <NUM_LIT:16> : ] <EOL> self . assertEqual ( self . loader . _fix_row ( row ) , fixed ) <EOL> def test_parse_results_row_general ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> candidates = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ] <EOL> common_kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> results = self . loader . _parse_result_row ( row , candidates , county , <EOL> county_ocd_id , ** common_kwargs ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , candidates [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:5> ] ) <EOL> self . assertEqual ( result . reporting_level , "<STR_LIT>" ) <EOL> self . assertEqual ( result . jurisdiction , row [ <NUM_LIT:0> ] ) <EOL> result = results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , candidates [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ - <NUM_LIT:6> ] ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> results = self . loader . _parse_result_row ( row , candidates , county , <EOL> county_ocd_id , ** common_kwargs ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> result = results [ <NUM_LIT:0> ] <EOL> self . assertEqual ( result . full_name , candidates [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ <NUM_LIT:5> ] ) <EOL> self . assertEqual ( result . reporting_level , "<STR_LIT>" ) <EOL> self . assertEqual ( result . jurisdiction , common_kwargs [ '<STR_LIT>' ] ) <EOL> result = results [ - <NUM_LIT:1> ] <EOL> self . assertEqual ( result . full_name , candidates [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . votes , row [ - <NUM_LIT:6> ] ) <EOL> def test_is_last_contest_row ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> reporting_level = '<STR_LIT>' <EOL> self . assertEqual ( self . loader . _is_last_contest_result ( row , <EOL> reporting_level ) , True ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> reporting_level = '<STR_LIT>' <EOL> self . assertEqual ( self . loader . _is_last_contest_result ( row , <EOL> reporting_level ) , False ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> reporting_level = '<STR_LIT>' <EOL> self . assertEqual ( self . loader . _is_last_contest_result ( row , <EOL> reporting_level ) , True ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> reporting_level = '<STR_LIT>' <EOL> self . assertEqual ( self . loader . _is_last_contest_result ( row , <EOL> reporting_level ) , False ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> reporting_level = '<STR_LIT>' <EOL> self . assertEqual ( self . loader . _is_last_contest_result ( row , <EOL> reporting_level ) , False ) <EOL> def test_parse_votes_type ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT:1.0> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _parse_votes_type ( row ) , '<STR_LIT>' ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _parse_votes_type ( row ) , None ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _parse_votes_type ( row ) , None ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _parse_votes_type ( row ) , '<STR_LIT>' ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _parse_votes_type ( row ) , '<STR_LIT>' ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEqual ( self . loader . _parse_votes_type ( row ) , None ) <EOL> class TestExcelPrecinct2013Loader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2013ResultLoader ( ) <EOL> def test_parse_office_row ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district = self . loader . _parse_office_row ( row ) <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , "<STR_LIT>" ) <EOL> row = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> office , district = self . loader . _parse_office_row ( row ) <EOL> self . assertEqual ( office , "<STR_LIT>" ) <EOL> self . assertEqual ( district , "<STR_LIT>" ) <EOL> def test_parse_candidates_row ( self ) : <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> expected_candidates = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) <EOL> ] <EOL> candidates = self . loader . _parse_candidates_row ( row ) <EOL> self . assertEqual ( candidates , expected_candidates ) <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> expected_candidates = [ <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ] <EOL> candidates = self . loader . _parse_candidates_row ( row ) <EOL> self . assertEqual ( candidates , expected_candidates ) <EOL> def test_parse_result_row ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = "<STR_LIT>" <EOL> candidates = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) <EOL> ] <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row , candidates , county , county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> for r in results : <EOL> self . assertEqual ( r . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( r . jurisdiction , row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> result = next ( r for r in results if r . full_name == '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , <NUM_LIT:3> ) <EOL> self . assertEqual ( result . party , "<STR_LIT>" ) <EOL> row = [ u'<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row , candidates , county , county_ocd_id ) <EOL> for r in results : <EOL> self . assertEqual ( r . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( r . jurisdiction , county ) <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = "<STR_LIT>" <EOL> candidates = [ <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , None ) , <EOL> ] <EOL> row = [ u'<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , u'<STR_LIT>' ] <EOL> results = self . loader . _parse_result_row ( row , candidates , county , county_ocd_id ) <EOL> self . assertEqual ( len ( results ) , len ( candidates ) ) <EOL> for r in results : <EOL> self . assertEqual ( r . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( r . jurisdiction , row [ <NUM_LIT:0> ] . strip ( ) ) <EOL> result = next ( r for r in results if r . full_name == '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> result = next ( r for r in results if r . full_name == '<STR_LIT>' ) <EOL> self . assertEqual ( result . votes , <NUM_LIT> ) <EOL> row = [ u'<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0.0> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row , candidates , county , county_ocd_id ) <EOL> for r in results : <EOL> self . assertEqual ( r . reporting_level , '<STR_LIT>' ) <EOL> self . assertEqual ( r . jurisdiction , county ) <EOL> class TestExcellPrecinct2014Loader ( LoaderPrepMixin , TestCase ) : <EOL> def setUp ( self ) : <EOL> self . loader = ExcelPrecinct2014ResultLoader ( ) <EOL> def test_parse_jurisdictions ( self ) : <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> expected = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ] <EOL> jurisdictions = self . loader . _parse_jurisdictions ( row ) <EOL> self . assertEqual ( jurisdictions , expected ) <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' ] <EOL> expected = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ] <EOL> def test_parse_jurisdiction ( self ) : <EOL> test_data = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ] <EOL> for expected in test_data : <EOL> val = expected [ <NUM_LIT:0> ] <EOL> result = self . loader . _parse_jurisdiction ( val ) <EOL> self . assertEqual ( result , expected ) <EOL> def test_parse_result_row ( self ) : <EOL> county = "<STR_LIT>" <EOL> county_ocd_id = '<STR_LIT>' <EOL> jurisdictions = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , None ) , <EOL> ] <EOL> common_kwargs = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row , jurisdictions , <EOL> county , county_ocd_id , ** common_kwargs ) <EOL> self . _test_result_common_fields ( row , jurisdictions , results ) <EOL> self . _test_result_at_index ( row , jurisdictions , results , <NUM_LIT:0> ) <EOL> self . _test_result_at_index ( row , jurisdictions , results , - <NUM_LIT:2> ) <EOL> self . _test_result_at_index ( row , jurisdictions , results , - <NUM_LIT:1> ) <EOL> row = [ u'<STR_LIT>' , u'<STR_LIT>' , u'<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> results = self . loader . _parse_result_row ( row , jurisdictions , <EOL> county , county_ocd_id , ** common_kwargs ) <EOL> self . _test_result_common_fields ( row , jurisdictions , results , '<STR_LIT:3>' ) <EOL> def _test_result_common_fields ( self , row , jurisdictions , results , <EOL> district = None ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( len ( results ) , len ( jurisdictions ) ) <EOL> full_name = row [ <NUM_LIT:1> ] . strip ( ) <EOL> party = row [ <NUM_LIT:2> ] . strip ( ) <EOL> primary_party = party [ <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> for result in results : <EOL> self . assertEqual ( result . full_name , full_name ) <EOL> self . assertEqual ( result . party , party ) <EOL> self . assertEqual ( result . primary_party , primary_party ) <EOL> self . assertEqual ( result . district , district ) <EOL> def _test_result_at_index ( self , row , jurisdictions , results , i ) : <EOL> """<STR_LIT>""" <EOL> result = results [ i ] <EOL> vote_index = i if i < <NUM_LIT:0> else i + <NUM_LIT:4> <EOL> votes_type = ( '<STR_LIT>' if jurisdictions [ i ] [ <NUM_LIT:2> ] == '<STR_LIT>' <EOL> else jurisdictions [ i ] [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( result . jurisdiction , jurisdictions [ i ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( result . reporting_level , jurisdictions [ i ] [ <NUM_LIT:1> ] ) <EOL> self . assertEqual ( result . votes_type , votes_type ) <EOL> self . assertEqual ( result . votes , row [ vote_index ] ) </s>
