def get_adv_boxscores(start, end): df = get_year_boxscores(start, end) if len(df) > 0: ids = get_year_boxscores( start, end)['boxscore'] if len(df) > 0 else pd.Series([]) df = pd.concat([Boxscore(id).dataframe for id in ids]) df['date'] = df['date'].apply( lambda x: datetime.strptime(x, '%B %d, %Y')) return df
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 test_game_summary_with_no_scores_returns_none(self): result = Boxscore(None)._parse_summary(pq( """<table id="line-score"> <tbody> <tr> <td class="right"></td> <td class="right"></td> </tr> <tr> <td class="right"></td> <td class="right"></td> </tr> </tbody> </table>""" )) assert result == { 'away': [None], 'home': [None] }
def boxscore(self): """ Returns an instance of the Boxscore class containing more detailed stats on the game. """ return Boxscore(self._boxscore)
from sportsreference.ncaab.boxscore import Boxscore game_data = Boxscore('2018-04-02-21-villanova') print(game_data.home_points) # Prints 79 print(game_data.away_points) # Prints 62 df = game_data.dataframe # Returns a Pandas DataFrame of game metrics ## access individual players for player in game_data.away_players: print(player.name, player.player_id, player.points, player.minutes_played) ## Output: # Muhammad-Ali Abdur-Rahkman muhammad-ali-abdur-rahkman-1 23 34 # Zavier Simpson zavier-simpson-1 10 34 # Moritz Wagner moritz-wagner-1 16 33 # Charles Matthews charles-matthews-1 6 33 # Isaiah Livers isaiah-livers-1 0 20 # Duncan Robinson duncan-robinson-1 0 22 # Jordan Poole jordan-poole-1 3 10 # Jon Teske jon-teske-1 2 7 # Jaaron Simmons jaaron-simmons-1 0 3 # Eli Brooks eli-brooks-1 0 3 # Ibi Watson ibi-watson-1 2 1 # Austin Davis austin-davis-1 0 0 # C.J. Baird cj-baird-1 0 0
def setup_method(self, *args, **kwargs): self.results = { 'date': 'November 24, 2017', 'location': 'Imperial Arena at Atlantis Resort, Paradise Island', 'winner': HOME, 'winning_name': 'Purdue', 'winning_abbr': 'PURDUE', 'losing_name': 'Arizona', 'losing_abbr': 'ARIZONA', 'pace': 71.8, 'away_ranking': 2, 'away_win_percentage': .500, 'away_wins': 3, 'away_losses': 3, 'away_minutes_played': 200, 'away_field_goals': 25, 'away_field_goal_attempts': 59, 'away_field_goal_percentage': .424, 'away_two_point_field_goals': 22, 'away_two_point_field_goal_attempts': 42, 'away_two_point_field_goal_percentage': .524, 'away_three_point_field_goals': 3, 'away_three_point_field_goal_attempts': 17, 'away_three_point_field_goal_percentage': .176, 'away_free_throws': 11, 'away_free_throw_attempts': 16, 'away_free_throw_percentage': .688, 'away_offensive_rebounds': 6, 'away_defensive_rebounds': 16, 'away_total_rebounds': 22, 'away_assists': 13, 'away_steals': 4, 'away_blocks': 3, 'away_turnovers': 11, 'away_personal_fouls': 20, 'away_points': 64, 'away_true_shooting_percentage': .480, 'away_effective_field_goal_percentage': .449, 'away_three_point_attempt_rate': .288, 'away_free_throw_attempt_rate': .271, 'away_offensive_rebound_percentage': 18.8, 'away_defensive_rebound_percentage': 72.7, 'away_total_rebound_percentage': 40.7, 'away_assist_percentage': 52.0, 'away_steal_percentage': 5.6, 'away_block_percentage': 9.4, 'away_turnover_percentage': 14.3, 'away_offensive_rating': 88.9, 'away_defensive_rating': 123.6, 'home_ranking': 18, 'home_win_percentage': .714, 'home_wins': 5, 'home_losses': 2, 'home_minutes_played': 200, 'home_field_goals': 31, 'home_field_goal_attempts': 54, 'home_field_goal_percentage': .574, 'home_two_point_field_goals': 20, 'home_two_point_field_goal_attempts': 32, 'home_two_point_field_goal_percentage': .625, 'home_three_point_field_goals': 11, 'home_three_point_field_goal_attempts': 22, 'home_three_point_field_goal_percentage': .500, 'home_free_throws': 16, 'home_free_throw_attempts': 21, 'home_free_throw_percentage': .762, 'home_offensive_rebounds': 6, 'home_defensive_rebounds': 26, 'home_total_rebounds': 32, 'home_assists': 19, 'home_steals': 6, 'home_blocks': 7, 'home_turnovers': 14, 'home_personal_fouls': 19, 'home_points': 89, 'home_true_shooting_percentage': .696, 'home_effective_field_goal_percentage': .676, 'home_three_point_attempt_rate': .407, 'home_free_throw_attempt_rate': .389, 'home_offensive_rebound_percentage': 27.3, 'home_defensive_rebound_percentage': 81.3, 'home_total_rebound_percentage': 59.3, 'home_assist_percentage': 61.3, 'home_steal_percentage': 8.3, 'home_block_percentage': 16.7, 'home_turnover_percentage': 18.1, 'home_offensive_rating': 123.6, 'home_defensive_rating': 88.9 } flexmock(utils) \ .should_receive('_todays_date') \ .and_return(MockDateTime(YEAR, MONTH)) self.boxscore = Boxscore('2017-11-24-21-purdue')
def setup_method(self, *args, **kwargs): flexmock(Boxscore) \ .should_receive('_parse_game_data') \ .and_return(None) self.boxscore = Boxscore(None)
class TestNCAABBoxscore: @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=75) fake_home_points = PropertyMock(return_value=70) 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=70) fake_home_points = PropertyMock(return_value=75) 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_di_is_home(self): expected_name = 'Home Name' test_name = '<a>cbb/schools</a>Home Name' fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_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_non_di_is_home(self): expected_name = 'Home Name' test_name = 'Home Name' fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_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_di_is_away(self): expected_name = 'Away Name' test_name = '<a>cbb/schools</a>Away Name' fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_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_name_non_di_is_away(self): expected_name = 'Away Name' test_name = 'Away Name' fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_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_di_is_home(self): expected_name = 'Home' test_name = '<a>cbb/schools</a>HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_non_di_is_home(self): expected_name = 'HOME' test_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_di_is_away(self): expected_name = 'AWAY' test_name = '<a>cbb/schools</a>AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_non_di_is_away(self): expected_name = 'AWAY' test_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.winning_abbr == expected_name def test_losing_name_di_is_home(self): expected_name = 'Home Name' test_name = '<a>cbb/schools</a>Home Name' fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_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_non_di_is_home(self): expected_name = 'Home Name' test_name = 'Home Name' fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_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_di_is_away(self): expected_name = 'Away Name' test_name = '<a>cbb/schools</a>Away Name' fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_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_name_non_di_is_away(self): expected_name = 'Away Name' test_name = 'Away Name' fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_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_di_is_home(self): expected_name = 'HOME' test_name = '<a>cbb/schools</a>HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_non_di_is_home(self): expected_name = 'HOME' test_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_di_is_away(self): expected_name = 'AWAY' test_name = '<a>cbb/schools</a>AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_non_di_is_away(self): expected_name = 'AWAY' test_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.losing_abbr == expected_name def test_invalid_away_record_returns_default_wins(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._away_record = fake_record assert self.boxscore.away_wins == 0 def test_invalid_away_record_returns_default_losses(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._away_record = fake_record assert self.boxscore.away_losses == 0 def test_invalid_home_record_returns_default_wins(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._home_record = fake_record assert self.boxscore.home_wins == 0 def test_invalid_home_record_returns_default_losses(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._home_record = fake_record assert self.boxscore.home_losses == 0 def test_invalid_url_returns_none(self): result = Boxscore(None)._retrieve_html_page('') assert result is None def test_parsing_name_for_non_di_school(self): name = 'Away name' boxscore = MockBoxscore(name) result = self.boxscore._parse_name('away_name', boxscore) assert result == name def test_no_home_free_throw_percentage_returns_default(self): fake_percentage = PropertyMock(return_value='') type(self.boxscore)._home_free_throw_percentage = fake_percentage assert self.boxscore.home_free_throw_percentage is None def test_no_away_free_throw_percentage_returns_default(self): fake_percentage = PropertyMock(return_value='') type(self.boxscore)._away_free_throw_percentage = fake_percentage assert self.boxscore.away_free_throw_percentage is None def test_empty_boxscore_class_returns_dataframe_of_none(self): fake_points = PropertyMock(return_value=None) type(self.boxscore)._home_points = fake_points type(self.boxscore)._away_points = fake_points assert self.boxscore._home_points is None assert self.boxscore._away_points is None assert self.boxscore.dataframe is None def test_away_win_percentage_no_games_played_returns_default(self): fake_games = PropertyMock(return_value=0) type(self.boxscore).away_wins = fake_games type(self.boxscore).away_losses = fake_games assert self.boxscore.away_wins == 0 assert self.boxscore.away_losses == 0 assert self.boxscore.away_win_percentage == 0.0 def test_home_win_percentage_no_games_played_returns_default(self): fake_games = PropertyMock(return_value=0) type(self.boxscore).home_wins = fake_games type(self.boxscore).home_losses = fake_games assert self.boxscore.home_wins == 0 assert self.boxscore.home_losses == 0 assert self.boxscore.home_win_percentage == 0.0 def test_ranking_with_no_boxscores(self): ranking = self.boxscore._parse_ranking('home_ranking', MockBoxscore('')) assert ranking is None
def test_invalid_url_returns_none(self): result = Boxscore(None)._retrieve_html_page('') assert result is None
class TestNCAABBoxscore: @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=75) fake_home_points = PropertyMock(return_value=70) 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=70) fake_home_points = PropertyMock(return_value=75) 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_di_is_home(self): expected_name = 'Home Name' test_name = '<a>cbb/schools</a>Home Name' fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_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_non_di_is_home(self): expected_name = 'Home Name' test_name = 'Home Name' fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_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_di_is_away(self): expected_name = 'Away Name' test_name = '<a>cbb/schools</a>Away Name' fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_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_name_non_di_is_away(self): expected_name = 'Away Name' test_name = 'Away Name' fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_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_di_is_home(self): expected_name = 'Home' test_name = '<a>cbb/schools</a>HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_non_di_is_home(self): expected_name = 'HOME' test_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_di_is_away(self): expected_name = 'AWAY' test_name = '<a>cbb/schools</a>AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.winning_abbr == expected_name def test_winning_abbr_non_di_is_away(self): expected_name = 'AWAY' test_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.winning_abbr == expected_name def test_losing_name_di_is_home(self): expected_name = 'Home Name' test_name = '<a>cbb/schools</a>Home Name' fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_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_non_di_is_home(self): expected_name = 'Home Name' test_name = 'Home Name' fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_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_di_is_away(self): expected_name = 'Away Name' test_name = '<a>cbb/schools</a>Away Name' fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_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_name_non_di_is_away(self): expected_name = 'Away Name' test_name = 'Away Name' fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_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_di_is_home(self): expected_name = 'HOME' test_name = '<a>cbb/schools</a>HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_non_di_is_home(self): expected_name = 'HOME' test_name = 'HOME' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=AWAY) fake_home_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._home_name = fake_home_name assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_di_is_away(self): expected_name = 'AWAY' test_name = '<a>cbb/schools</a>AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.losing_abbr == expected_name def test_losing_abbr_non_di_is_away(self): expected_name = 'AWAY' test_name = 'AWAY' flexmock(utils) \ .should_receive('_parse_abbreviation') \ .and_return(expected_name) fake_winner = PropertyMock(return_value=HOME) fake_away_name = PropertyMock(return_value=MockName(test_name)) type(self.boxscore).winner = fake_winner type(self.boxscore)._away_name = fake_away_name assert self.boxscore.losing_abbr == expected_name def test_invalid_away_record_returns_default_wins(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._away_record = fake_record assert self.boxscore.away_wins == 0 def test_invalid_away_record_returns_default_losses(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._away_record = fake_record assert self.boxscore.away_losses == 0 def test_invalid_home_record_returns_default_wins(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._home_record = fake_record assert self.boxscore.home_wins == 0 def test_invalid_home_record_returns_default_losses(self): fake_record = PropertyMock(return_value='Purdue (1)') type(self.boxscore)._home_record = fake_record assert self.boxscore.home_losses == 0 def test_invalid_url_returns_none(self): result = Boxscore(None)._retrieve_html_page('') assert result is None def test_parsing_name_for_non_di_school(self): name = 'Away name' boxscore = MockBoxscore(name) result = self.boxscore._parse_name('away_name', boxscore) assert result == name def test_no_home_free_throw_percentage_returns_default(self): fake_percentage = PropertyMock(return_value='') type(self.boxscore)._home_free_throw_percentage = fake_percentage assert self.boxscore.home_free_throw_percentage is None def test_no_away_free_throw_percentage_returns_default(self): fake_percentage = PropertyMock(return_value='') type(self.boxscore)._away_free_throw_percentage = fake_percentage assert self.boxscore.away_free_throw_percentage is None def test_empty_boxscore_class_returns_dataframe_of_none(self): fake_points = PropertyMock(return_value=None) type(self.boxscore)._home_points = fake_points type(self.boxscore)._away_points = fake_points assert self.boxscore._home_points is None assert self.boxscore._away_points is None assert self.boxscore.dataframe is None def test_away_win_percentage_no_games_played_returns_default(self): fake_games = PropertyMock(return_value=0) type(self.boxscore).away_wins = fake_games type(self.boxscore).away_losses = fake_games assert self.boxscore.away_wins == 0 assert self.boxscore.away_losses == 0 assert self.boxscore.away_win_percentage == 0.0 def test_home_win_percentage_no_games_played_returns_default(self): fake_games = PropertyMock(return_value=0) type(self.boxscore).home_wins = fake_games type(self.boxscore).home_losses = fake_games assert self.boxscore.home_wins == 0 assert self.boxscore.home_losses == 0 assert self.boxscore.home_win_percentage == 0.0 def test_ranking_with_no_boxscores(self): ranking = self.boxscore._parse_ranking('home_ranking', MockBoxscore('')) assert ranking is None def test_ncaab_game_info(self): fields = { 'date': 'November 9, 2018', 'location': 'WVU Coliseum, Morgantown, West Virginia' } mock_field = """November 9, 2018 WVU Coliseum, Morgantown, West Virginia Logos via Sports Logos.net / About logos """ m = MockBoxscoreData(MockField(mock_field)) for field, value in fields.items(): result = self.boxscore._parse_game_date_and_location(field, m) assert value == result def test_ncaab_partial_game_info(self): fields = { 'date': 'November 9, 2018', 'location': None } mock_field = """November 9, 2018 Logos via Sports Logos.net / About logos""" m = MockBoxscoreData(MockField(mock_field)) for field, value in fields.items(): result = self.boxscore._parse_game_date_and_location(field, m) assert value == result