From 73bab47a456b1ecde386d11967504201d42e0570 Mon Sep 17 00:00:00 2001 From: DesiPilla Date: Wed, 20 Dec 2023 15:43:39 -0500 Subject: [PATCH] tests: more test coverage --- tests/football/unit/test_league.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/football/unit/test_league.py b/tests/football/unit/test_league.py index f4f21424..e4b589d7 100644 --- a/tests/football/unit/test_league.py +++ b/tests/football/unit/test_league.py @@ -110,6 +110,11 @@ def test_standings_weekly(self, m): # final_standings = [team.team_id for team in league.standings()] # self.assertEqual(week13_standings, final_standings) + # Test invalid playoff seeding rule + with self.assertRaises(Exception): + league.settings.playoff_seed_tie_rule = "NOT_A_REAL_RULE" + league.standings(week=1) + def get_list_of_team_data(self, league: League, week: int): list_of_team_data = [] for team in league.teams: @@ -233,10 +238,8 @@ def test_sort_functions(self, m): league = League(self.league_id, self.season) + week1_teams_data = self.get_list_of_team_data(league, 1) week10_teams_data = self.get_list_of_team_data(league, 10) - list_of_team_data = [ - team for team in week10_teams_data if team["team_id"] in (1, 2) - ] division_record_dict = build_division_record_dict(week10_teams_data) # Assert that sort_by_win_pct is correct @@ -255,21 +258,32 @@ def test_sort_functions(self, m): sorted_list_of_team_data[i + 1]["points_for"], ) + # Assert that sort_by_head_to_head is correct - 1 team + sorted_list_of_team_data = sort_by_head_to_head(week10_teams_data[:1].copy()) + self.assertEqual(sorted_list_of_team_data == week10_teams_data[:1], True) + # Assert that sort_by_head_to_head is correct - 2 teams sorted_list_of_team_data = sort_by_head_to_head( [team for team in week10_teams_data if team["team_id"] in (1, 2)] ) self.assertEqual(sorted_list_of_team_data[0]["team_id"], 1) - # Assert that sort_by_head_to_head is correct - 3 teams + # Assert that sort_by_head_to_head is correct - 3 teams, valid sorted_list_of_team_data = sort_by_head_to_head( [team for team in week10_teams_data if team["team_id"] in (1, 2, 3)] ) - # Team 1 is undefeated vs team 2 self.assertEqual(sorted_list_of_team_data[0]["team_id"], 1) self.assertEqual(sorted_list_of_team_data[1]["team_id"], 3) self.assertEqual(sorted_list_of_team_data[2]["team_id"], 2) + # Assert that sort_by_head_to_head is correct - 3 teams, invalid + sorted_list_of_team_data = sort_by_head_to_head( + [team for team in week1_teams_data if team["team_id"] in (1, 2, 3)] + ) + self.assertEqual(sorted_list_of_team_data[0]["h2h_wins"], 0) + self.assertEqual(sorted_list_of_team_data[1]["h2h_wins"], 0) + self.assertEqual(sorted_list_of_team_data[2]["h2h_wins"], 0) + # Assert that sort_by_division_record is correct sorted_list_of_team_data = sort_by_division_record(week10_teams_data) for i in range(len(sorted_list_of_team_data) - 1):