def test_league_get_team_data(self, mock_get_league_request): mock_get_league_request.return_value = self.league_data league = HockeyLeague(self.league_id, self.season) expected_team = 'Team(The Return of the Captain)' actual_team = league.get_team_data(9) self.assertEqual(expected_team, repr(actual_team)) mock_get_league_request.assert_called_once()
def test_league_init(self): league = League(league_id=1, year=2020, espn_s2='espn_s2', swid='swid', username='******', password='******', testing=True, test_data=data) players = league.get_league_players() self.assertEqual(players.iloc[0]['player_name'], "Taylor Hall")
def test_league_stats(self): league = League(league_id=1, year=2020, espn_s2='espn_s2', swid='swid', username='******', password='******', testing=True, test_data=data) stats = league.get_league_player_stats() self.assertEqual(stats.iloc[0]['Owner_Name'], "firstName7 lastName7") self.assertEqual(stats.iloc[0]['statSourceId'], 2) self.assertEqual(stats.iloc[0]['seasonID'], 2020)
def test_league_recent_activity(self, mock_get_league_request, mock_league_get_request): with open('tests/hockey/unit/data/recent_activity_data.json') as file: activity_data = json.loads(file.read()) mock_get_league_request.return_value = self.league_data mock_league_get_request.return_value = activity_data league = HockeyLeague(self.league_id, self.season) first_expected_activity = 'Activity((Team(2 Minutes for.. Rooping?),FA ADDED,Jake DeBrusk))' actual_activities = league.recent_activity() self.assertEqual(first_expected_activity, repr(actual_activities[0])) mock_get_league_request.assert_called_once() mock_league_get_request.assert_called_once()
def test_league_free_agency(self, mock_get_league_request, mock_league_get_request): with open('tests/hockey/unit/data/free_agent_data.json') as file: free_agents_data = json.loads(file.read()) mock_get_league_request.return_value = self.league_data mock_league_get_request.return_value = free_agents_data league = HockeyLeague(self.league_id, self.season) first_expected_free_agent = 'Player(Brendan Gallagher)' actual_free_agents = league.free_agents() self.assertEqual(first_expected_free_agent, repr(actual_free_agents[0])) mock_get_league_request.assert_called_once() mock_league_get_request.assert_called_once()
def test_league_scoreboard(self, mock_get_league_request, mock_league_get_request): with open('tests/hockey/unit/data/matchup_data.json') as file: matchup_data = json.loads(file.read()) mock_get_league_request.return_value = self.league_data mock_league_get_request.return_value = matchup_data league = HockeyLeague(self.league_id, self.season) first_expected_matchup = 'Matchup(Team(Drop Trou and Shattenkirk) 9.0 - 1.0 Team(Eichel Scott Paper Company ))' actual_matchups = league.scoreboard() self.assertEqual(first_expected_matchup, repr(actual_matchups[0])) mock_get_league_request.assert_called_once() mock_league_get_request.assert_called_once()
def test_league_init(self): league = League(77421173, 2021) self.assertEqual(league.scoringPeriodId, 72) self.assertEqual(league.start_date.year, 2021) self.assertEqual(league.start_date.month, 1) self.assertEqual(league.start_date.day, 13)
def test_league_box_scores(self, mock_get_league_request, mock_league_get_request): with open('tests/hockey/unit/data/box_score_data.json') as file: box_score_data = json.loads(file.read()) mock_get_league_request.return_value = self.league_data mock_league_get_request.return_value = box_score_data league = HockeyLeague(self.league_id, self.season) first_box_score = 'Box Score(12 at Team(2 Minutes for.. Rooping?))' actual_box_scores = league.box_scores() self.assertEqual(len(actual_box_scores), 6) self.assertEqual(first_box_score, repr(actual_box_scores[0])) mock_get_league_request.assert_called_once() mock_league_get_request.assert_called_once()
# and accumulate number of won/tied cats if len(cat) == 2: cats_won += int(player_stats[i] > opponent_stats[i]) else: cats_won += int(player_stats[i] < opponent_stats[i]) cats_tied += int(player_stats[i] == opponent_stats[i]) W = int(cats_won > len(CATEGORIES) - cats_tied - cats_won) L = int(cats_won < len(CATEGORIES) - cats_tied - cats_won) T = int(not (W or L)) return np.array([W, L, T, cats_won]) if __name__ == "__main__": maythebestteamwin = League(league_id=LEAGUE_ID, year=2021, espn_s2=ESPN_S2, swid=SWID) curr_week = maythebestteamwin.currentMatchupPeriod # Collect Weekly scores in all categories for each player # axis 0 (rows): player score for a given week (player_id = row_idx + 1) # axis 1 (columns): categories # axis 3 ("depth"): matchup week weekly_cat_scores = np.zeros((12, 12, curr_week - 1)) extract_matchup_scores(maythebestteamwin, weekly_cat_scores) rr_cumulative = pd.DataFrame() with pd.option_context('display.max_rows', 20, 'display.max_columns', 20): #print(week_1_scores) for i in range(curr_week-1):