def test_nfl_boxscore_string_representation(self): expected = ('Boxscore for Philadelphia Eagles at New England Patriots ' '(Sunday Feb 4, 2018)') boxscore = Boxscore(BOXSCORE) assert boxscore.__repr__() == expected
def get_game_stats_for_season(self): week_list = list(range(1, 18)) nfl_game_stats = pd.DataFrame() year = 2019 for week in week_list: week_str = str(week) year_str = str(year) date = week_str + "-" + year_str week_results = Boxscores(week, year) week_stats_df = pd.DataFrame() for game in week_results.games[date]: game_id = game['boxscore'] game_stats = Boxscore(game_id) game_results = pd.DataFrame(game, index=[0]) away_team_stats, home_team_stats = self.game_stats_cleanup(game_results, game_stats) away_team_stats['week'] = week home_team_stats['week'] = week week_stats_df = pd.concat([week_stats_df, away_team_stats]) week_stats_df = pd.concat([week_stats_df, home_team_stats]) nfl_game_stats = pd.concat([nfl_game_stats, week_stats_df]) return nfl_game_stats
def generate_probabilities(self, week, team_dict): self.output_text.delete(1.0, "end-1c") year = 2019 home_team = "" away_team = "" data = pandas.read_excel(r'NFLelo2015-2019week5.xlsx', sheet_name='2019') df = pandas.DataFrame(data, columns=['Team', 'Elo Rating']) ratings_dict = dict(zip(df['Team'], df['Elo Rating'])) game_codes = get_game_codes(week, year) for game in game_codes: box = Boxscore(game) for name, abv in team_dict.items(): if abv == box.home_abbreviation.upper(): home_team = name print(home_team) if abv == box.away_abbreviation.upper(): away_team = name print(away_team) elo_difference = ratings_dict[home_team] - ratings_dict[away_team] spread = str(round(-elo_difference / 25)) if spread == '0': spread = 'even' if '-' not in spread: if spread == 'even': spread = spread else: spread = '+' + spread home_probability = round(100 * (1 / ((math.pow(10, -elo_difference / 400)) + 1)), 2) away_probability = round(100 - home_probability, 2) self.output_text.insert("end-1c", '{:24s}{:5}\n{:24s}{:5}\nElo-based Spread: {:3}\n\n' .format(away_team, away_probability, home_team, home_probability, spread))
def get_games_data(season): games_data = [] weeks = Boxscores(start_week, season, end_week) for key in weeks.games: for game in weeks.games[key]: print("Fetching {} data".format(game['boxscore'])) games_data.append(Boxscore(game['boxscore']).dataframe) return pd.concat(games_data)
def test_nfl_boxscore_players(self): boxscore = Boxscore(BOXSCORE) assert len(boxscore.home_players) == 27 assert len(boxscore.away_players) == 29 for player in boxscore.home_players: assert not player.dataframe.empty for player in boxscore.away_players: assert not player.dataframe.empty
def test_invalid_url_yields_empty_class(self): flexmock(Boxscore) \ .should_receive('_retrieve_html_page') \ .and_return(None) boxscore = Boxscore(BOXSCORE) for key, value in boxscore.__dict__.items(): if key == '_uri': continue assert value is None
def create_boxscore_dfs(season, start, end): b_games = [] player_dict = dict() player_stats = [] box_id = [] box_keys = {} box_games = Boxscores(start, season, end).games for k, v in box_games.items(): for box in v: box_keys[box['boxscore']] = k.split('-')[0] box_id.append(box['boxscore']) #box_id = [ids['boxscore'] for v in box_games.values() for ids in v] for ids in box_id: box = Boxscore(ids) for p in box.home_players: if p not in player_dict.keys(): player_dict[p.name] = p.player_id temp_hplayer_df = p.dataframe temp_hplayer_df['box_id'] = ids temp_hplayer_df['team'] = box.home_abbreviation temp_hplayer_df['name'] = p.name player_stats.append(temp_hplayer_df) for p in box.away_players: if p not in player_dict.keys(): player_dict[p.name] = p.player_id temp_aplayer_df = p.dataframe temp_aplayer_df['box_id'] = ids temp_aplayer_df['team'] = box.away_abbreviation temp_aplayer_df['name'] = p.name player_stats.append(temp_aplayer_df) b_games.append(box.dataframe) boxscore_stats_df = pd.concat(player_stats) box_df = pd.concat(b_games) # Temp cut out to try and work it into the first nested loop #box_keys ={} #for k,v in box_games.items(): # for box in v: # box_keys[box['boxscore']] = k.split('-')[0] # creates in the boxscore_stats_df a column for what week the game was played boxscore_stats_df['week'] = boxscore_stats_df['box_id'].map( lambda x: box_keys[x]) # Creates a column for the week the game was played box_df = box_df.reset_index().rename(columns={'index': 'box_id'}) box_df['week'] = box_df['box_id'].map(lambda x: box_keys[x]) box_df = box_df.set_index('box_id') return boxscore_stats_df, box_df, player_dict
def test_game_summary_with_no_scores_returns_none(self): result = Boxscore(None)._parse_summary( pq("""<table class="linescore nohover stats_table no_freeze"> <tbody> <tr> <td class="center"></td> <td class="center"></td> </tr> <tr> <td class="center"></td> <td class="center"></td> </tr> </tbody> </table>""")) assert result == {'away': [None], 'home': [None]}
def setup_method(self, *args, **kwargs): flexmock(Boxscore) \ .should_receive('_parse_game_data') \ .and_return(None) self.boxscore = Boxscore(None)
def test_url_404_page_returns_none(self): result = Boxscore(None)._retrieve_html_page('404') assert result is None
def test_invalid_url_returns_none(self, *args, **kwargs): result = Boxscore(None)._retrieve_html_page('bad') assert result is None
def boxscore(self): """ Returns an instance of the Boxscore class containing more detailed stats on the game. """ return Boxscore(self._boxscore)
def setup_method(self, *args, **kwargs): self.results = { 'date': 'Sunday Feb 4, 2018', 'time': '6:30pm', 'datetime': datetime(2018, 2, 4, 18, 30), 'stadium': 'U.S. Bank Stadium', 'attendance': 67612, 'duration': '3:46', 'winner': AWAY, 'winning_name': 'Philadelphia Eagles', 'winning_abbr': 'PHI', 'losing_name': 'New England Patriots', 'losing_abbr': 'NWE', 'won_toss': 'Patriots (deferred)', 'weather': None, 'vegas_line': 'New England Patriots -4.5', 'surface': 'Sportturf', 'roof': 'Dome', 'over_under': '48.5 (over)', 'away_points': 41, 'away_first_downs': 25, 'away_rush_attempts': 27, 'away_rush_yards': 164, 'away_rush_touchdowns': 1, 'away_pass_completions': 29, 'away_pass_attempts': 44, 'away_pass_yards': 374, 'away_pass_touchdowns': 4, 'away_interceptions': 1, 'away_times_sacked': 0, 'away_yards_lost_from_sacks': 0, 'away_net_pass_yards': 374, 'away_total_yards': 538, 'away_fumbles': 0, 'away_fumbles_lost': 0, 'away_turnovers': 1, 'away_penalties': 6, 'away_yards_from_penalties': 35, 'away_third_down_conversions': 10, 'away_third_down_attempts': 16, 'away_fourth_down_conversions': 2, 'away_fourth_down_attempts': 2, 'away_time_of_possession': '34:04', 'home_points': 33, 'home_first_downs': 29, 'home_rush_attempts': 22, 'home_rush_yards': 113, 'home_rush_touchdowns': 1, 'home_pass_completions': 28, 'home_pass_attempts': 49, 'home_pass_yards': 505, 'home_pass_touchdowns': 3, 'home_interceptions': 0, 'home_times_sacked': 1, 'home_yards_lost_from_sacks': 5, 'home_net_pass_yards': 500, 'home_total_yards': 613, 'home_fumbles': 1, 'home_fumbles_lost': 1, 'home_turnovers': 1, 'home_penalties': 1, 'home_yards_from_penalties': 5, 'home_third_down_conversions': 5, 'home_third_down_attempts': 10, 'home_fourth_down_conversions': 1, 'home_fourth_down_attempts': 2, 'home_time_of_possession': '25:56', } flexmock(utils) \ .should_receive('_todays_date') \ .and_return(MockDateTime(YEAR, MONTH)) self.boxscore = Boxscore(BOXSCORE)
def calculate_elo(self, team_dict, abbrev_dict, start_year, end_year, end_week): endw = 22 week = 1 excel_name = 'NFLelo' + start_year + '-' + end_year + 'week' + end_week + '.xlsx' wb = xlsxwriter.Workbook(excel_name) start_year = int(start_year) end_year = int(end_year) # CONSTANT K FOR ELO ALGO k = 30 p = re.compile("'(\\d{4}\\d+\\w+)'") team_objects = {} self.output_text.delete(1.0, "end-1c") for name, abbrev in team_dict.items(): new_team = teamobj.NflTeam(name, abbrev) team_objects.update({abbrev: new_team}) for year in range(start_year, end_year + 1): # Initialize new excel sheet sheet = wb.add_worksheet(str(year)) sheet.set_column(0, 0, 24) sheet.set_column(1, 1, 10) sheet.write(0, 0, "Team") sheet.write(0, 1, "Elo Rating") sheet.write(0, 2, "Wins") sheet.write(0, 3, "Losses") if year > start_year: team_objects = elo_regression(team_objects) # will iterate through weeks 1-21 if year == end_year: endw = int(end_week) + 1 for week in range(1, endw): print("----- YEAR ", year, " | WEEK:", week, "-----") selected_week = Boxscores(week, year) game_codes = p.findall(str(selected_week.games.values())) for game in game_codes: box = Boxscore(game) winner = team_objects[box.winning_abbr] loser = team_objects[box.losing_abbr] # elo prob_winner = self.probability(loser.elo, winner.elo) prob_loser = self.probability(winner.elo, loser.elo) winner.elo = winner.elo + k * (1 - prob_winner) loser.elo = loser.elo + k * (0 - prob_loser) welo = round(winner.elo, 4) lelo = round(loser.elo, 4) print(winner.name, str(welo)) print(loser.name, str(lelo)) # update elo at end of year to regress 1/3 to mean if year == end_year and week == 21: team_objects = elo_regression(team_objects) n = 1 excel_dict = OrderedDict(sorted(team_objects.items(), key=lambda x: x[1].elo, reverse=True)) for abv, tobj in excel_dict.items(): for name, ab in team_dict.items(): if ab == abv: sheet.write(n, 0, name) sheet.write(n, 1, tobj.elo) # SportsReference Library Team Lookups is Currently Broken as of 11/25/19 # for team in Teams(year): # if team.abbreviation == abv: # sheet.write(n, 2, team.wins) # sheet.write(n, 3, team.losses) n = n + 1 # SportsReference Library Team Lookups is Currently Broken as of 11/25/19 # rank = 1 # newdict = OrderedDict(sorted(team_objects.items(), key=lambda x: x[1].elo, reverse=True)) # for abv, tobj in newdict.items(): # name = abbrev_dict[abv] # self.output_text.insert("end-1c", '{:4s}{:24s}{:9s}\n'.format(str(rank) + '.', name, str(tobj.elo))) # rank = rank + 1 # Close Excel Workbook wb.close()
class TestNFLBoxscore: @patch('requests.get', side_effect=mock_pyquery) def setup_method(self, *args, **kwargs): flexmock(Boxscore) \ .should_receive('_parse_game_data') \ .and_return(None) self.boxscore = Boxscore(None) def test_away_team_wins(self): fake_away_points = PropertyMock(return_value=28) fake_home_points = PropertyMock(return_value=21) type(self.boxscore)._away_points = fake_away_points type(self.boxscore)._home_points = fake_home_points assert self.boxscore.winner == AWAY def test_home_team_wins(self): fake_away_points = PropertyMock(return_value=21) fake_home_points = PropertyMock(return_value=28) type(self.boxscore)._away_points = fake_away_points type(self.boxscore)._home_points = fake_home_points assert self.boxscore.winner == HOME def test_winning_name_is_home(self): expected_name = 'Home Name' fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.winning_name == expected_name def test_winning_name_is_away(self): expected_name = 'Away Name' fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.winning_name == expected_name def test_winning_abbr_is_home(self): expected_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_home_abbr = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_abbr = fake_home_abbr assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_is_away(self): expected_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_away_abbr = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_abbr = fake_away_abbr assert self.boxscore.winning_abbr == expected_name def test_losing_name_is_home(self): expected_name = 'Home Name' fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.losing_name == expected_name def test_losing_name_is_away(self): expected_name = 'Away Name' fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.losing_name == expected_name def test_losing_abbr_is_home(self): expected_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_home_abbr = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_abbr = fake_home_abbr assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_is_away(self): expected_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_away_abbr = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_abbr = fake_away_abbr assert self.boxscore.losing_abbr == expected_name @patch('requests.get', side_effect=mock_pyquery) def test_invalid_url_returns_none(self, *args, **kwargs): result = Boxscore(None)._retrieve_html_page('bad') assert result is None def test_url_404_page_returns_none(self): result = Boxscore(None)._retrieve_html_page('404') assert result is None def test_no_class_information_returns_dataframe_of_none(self): mock_points = PropertyMock(return_value=None) type(self.boxscore)._home_points = mock_points type(self.boxscore)._away_points = mock_points assert self.boxscore.dataframe is None def test_empty_attribute_returns_none(self): fake_rushes = PropertyMock(return_value=None) type(self.boxscore)._away_rush_attempts = fake_rushes assert self.boxscore.away_rush_attempts is None def test_non_int_value_returns_none(self): fake_rushes = PropertyMock(return_value='bad') type(self.boxscore)._away_rush_attempts = fake_rushes assert self.boxscore.away_rush_attempts is None def test_nfl_game_information(self): fields = { 'attendance': 62881, 'date': 'Thursday Nov 8, 2018', 'duration': '2:49', 'stadium': 'Heinz Field', 'time': '8:20pm' } mock_field = """Thursday Nov 8, 2018 Start Time: 8:20pm Stadium: Heinz Field Attendance: 62,881 Time of Game: 2:49 Logos via Sports Logos.net / About logos """ m = MockBoxscoreData(MockField(mock_field)) self.boxscore._parse_game_date_and_location(m) for field, value in fields.items(): assert getattr(self.boxscore, field) == value def test_nfl_game_limited_information(self): fields = { 'attendance': 22000, 'date': 'Sunday Sep 8, 1940', 'duration': None, 'stadium': 'Forbes Field', 'time': None } mock_field = """Sunday Sep 8, 1940 Stadium: Forbes Field Attendance: 22,000 Logos via Sports Logos.net / About logos """ m = MockBoxscoreData(MockField(mock_field)) self.boxscore._parse_game_date_and_location(m) for field, value in fields.items(): assert getattr(self.boxscore, field) == value def test_nfl_away_abbreviation(self): away_name = PropertyMock(return_value='<a href="/teams/kan/2018.htm" \ itemprop="name">Kansas City Chiefs</a>') type(self.boxscore)._away_name = away_name assert self.boxscore.away_abbreviation == 'kan' def test_nfl_home_abbreviation(self): home_name = PropertyMock(return_value='<a href="/teams/nwe/2018.htm" \ itemprop="name">New England Patriots</a>') type(self.boxscore)._home_name = home_name assert self.boxscore.home_abbreviation == 'nwe'
class TestNFLBoxscore: @patch('requests.get', side_effect=mock_pyquery) def setup_method(self, *args, **kwargs): flexmock(Boxscore) \ .should_receive('_parse_game_data') \ .and_return(None) self.boxscore = Boxscore(None) def test_away_team_wins(self): fake_away_points = PropertyMock(return_value=28) fake_home_points = PropertyMock(return_value=21) type(self.boxscore)._away_points = fake_away_points type(self.boxscore)._home_points = fake_home_points assert self.boxscore.winner == AWAY def test_home_team_wins(self): fake_away_points = PropertyMock(return_value=21) fake_home_points = PropertyMock(return_value=28) type(self.boxscore)._away_points = fake_away_points type(self.boxscore)._home_points = fake_home_points assert self.boxscore.winner == HOME def test_winning_name_is_home(self): expected_name = 'Home Name' fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.winning_name == expected_name def test_winning_name_is_away(self): expected_name = 'Away Name' fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.winning_name == expected_name def test_winning_abbr_is_home(self): expected_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) type(self.boxscore).winner = fake_winner assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_is_away(self): expected_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) type(self.boxscore).winner = fake_winner assert self.boxscore.winning_abbr == expected_name def test_losing_name_is_home(self): expected_name = 'Home Name' fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.losing_name == expected_name def test_losing_name_is_away(self): expected_name = 'Away Name' fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(expected_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.losing_name == expected_name def test_losing_abbr_is_home(self): expected_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) type(self.boxscore).winner = fake_winner assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_is_away(self): expected_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) type(self.boxscore).winner = fake_winner assert self.boxscore.losing_abbr == expected_name def test_game_summary_with_no_scores_returns_none(self): result = Boxscore(None)._parse_summary( pq("""<table class="linescore nohover stats_table no_freeze"> <tbody> <tr> <td class="center"></td> <td class="center"></td> </tr> <tr> <td class="center"></td> <td class="center"></td> </tr> </tbody> </table>""")) assert result == {'away': [None], 'home': [None]} @patch('requests.get', side_effect=mock_pyquery) def test_invalid_url_returns_none(self, *args, **kwargs): result = Boxscore(None)._retrieve_html_page('bad') assert result is None def test_url_404_page_returns_none(self): result = Boxscore(None)._retrieve_html_page('404') assert result is None def test_no_class_information_returns_dataframe_of_none(self): mock_points = PropertyMock(return_value=None) type(self.boxscore)._home_points = mock_points type(self.boxscore)._away_points = mock_points assert self.boxscore.dataframe is None def test_empty_attribute_returns_none(self): fake_rushes = PropertyMock(return_value=None) type(self.boxscore)._away_rush_attempts = fake_rushes assert self.boxscore.away_rush_attempts is None def test_non_int_value_returns_none(self): fake_rushes = PropertyMock(return_value='bad') type(self.boxscore)._away_rush_attempts = fake_rushes assert self.boxscore.away_rush_attempts is None def test_nfl_game_information(self): fields = { 'attendance': 62881, 'date': 'Thursday Nov 8, 2018', 'duration': '2:49', 'stadium': 'Heinz Field', 'time': '8:20pm' } mock_field = """Thursday Nov 8, 2018 Start Time: 8:20pm Stadium: Heinz Field Attendance: 62,881 Time of Game: 2:49 Logos via Sports Logos.net / About logos """ m = MockBoxscoreData(MockField(mock_field)) self.boxscore._parse_game_date_and_location(m) for field, value in fields.items(): assert getattr(self.boxscore, field) == value def test_nfl_game_limited_information(self): fields = { 'attendance': 22000, 'date': 'Sunday Sep 8, 1940', 'duration': None, 'stadium': 'Forbes Field', 'time': None } mock_field = """Sunday Sep 8, 1940 Stadium: Forbes Field Attendance: 22,000 Logos via Sports Logos.net / About logos """ m = MockBoxscoreData(MockField(mock_field)) self.boxscore._parse_game_date_and_location(m) for field, value in fields.items(): assert getattr(self.boxscore, field) == value def test_nfl_away_abbreviation(self): away_name = PropertyMock(return_value='<a href="/teams/kan/2018.htm" \ itemprop="name">Kansas City Chiefs</a>') type(self.boxscore)._away_name = away_name assert self.boxscore.away_abbreviation == 'kan' def test_nfl_home_abbreviation(self): home_name = PropertyMock(return_value='<a href="/teams/nwe/2018.htm" \ itemprop="name">New England Patriots</a>') type(self.boxscore)._home_name = home_name assert self.boxscore.home_abbreviation == 'nwe' def test_nfl_datetime_missing_time(self): date = PropertyMock(return_value='Sunday Oct 7, 2018') time = PropertyMock(return_value=None) type(self.boxscore)._date = date type(self.boxscore)._time = time assert self.boxscore.datetime == datetime(2018, 10, 7) def test_nfl_game_details(self): fields = { 'won_toss': 'Dolphins', 'roof': 'Outdoors', 'surface': 'Fieldturf', 'weather': '87 degrees, wind 4 mph', 'vegas_line': 'Cincinnati Bengals -6.5', 'over_under': '47.5 (under)' } mock_field = """<table id="game_info"> <tr><th data-stat="info">Won Toss</th><td data-stat="stat">Dolphins</td></tr> <tr><th data-stat="info">Roof</th><td data-stat="stat">outdoors</td></tr> <tr><th data-stat="info">Surface</th><td data-stat="stat">fieldturf </td></tr> <tr><th data-stat="info">Duration</th><td data-stat="stat">3:02</td></tr> <tr><th data-stat="info">Attendance</th><td data-stat="stat">52,708</td></tr> <tr><th data-stat="info">Weather</th> <td data-stat="stat">87 degrees, wind 4 mph</td></tr> <tr><th data-stat="info">Vegas Line</th> <td data-stat="stat">Cincinnati Bengals -6.5</td></tr> <tr><th data-stat="info">Over/Under</th> <td data-stat="stat">47.5 <b>(under)</b></td></tr> </table> """ self.boxscore._parse_game_details(pq(mock_field)) for field, value in fields.items(): assert getattr(self.boxscore, field) == value def test_finding_home_team_with_no_abbrs(self): mock_html = pq('<td data-stat="team">KAN</td>') abbr = PropertyMock(return_value='KAN') self.boxscore._home_abbr = None self.boxscore._away_abbr = None type(self.boxscore).home_abbreviation = abbr team = self.boxscore._find_home_or_away(mock_html) assert team == HOME def test_finding_away_team_with_no_abbrs(self): mock_html = pq('<td data-stat="team">HTX</td>') abbr = PropertyMock(return_value='KAN') self.boxscore._home_abbr = None self.boxscore._away_abbr = None type(self.boxscore).home_abbreviation = abbr team = self.boxscore._find_home_or_away(mock_html) assert team == AWAY def test_missing_abbreviations(self): table = '<table id="team_stats"><thead></thead></table>' output = self.boxscore._alt_abbreviations(pq(table)) assert output == (None, None)