def test_standings(self): for index, testdata in self.testdata.items(): tournament, teams = self.setup_testdata(testdata) for metrics in testdata["rankings"].keys(): with self.subTest(index=index, metrics=metrics): generator = TeamStandingsGenerator(metrics, self.rankings) with suppress_logs('standings.teams', logging.INFO), \ suppress_logs('standings.metrics', logging.INFO): standings = generator.generate( tournament.team_set.all()) self.assertEqual(len(standings), len(testdata["standings"])) self.assertEqual(standings.metric_keys, list(metrics)) for teamname, expected in testdata["standings"].items(): team = teams[teamname] standing = standings.get_standing(team) for metric in metrics: self.assertEqual(standing.metrics[metric], expected[metric]) ranked_teams = [ teams[x] for x in testdata["rankings"][metrics] ] self.assertEqual(ranked_teams, standings.get_instance_list())
def test_teamscore_field_points(self, result, testdata, scoresheet_type): for side in self.SIDES: points = 1 if side == testdata[scoresheet_type]['winner'] else 0 with suppress_logs('results.result', logging.WARNING): self.assertEqual(points, self._get_teamscore_in_db(side).points) self.assertEqual(points, result.teamscore_field_points(side))
def test_adj_on_adj_multiple_submission(self): debate = self._create_debate((0, 1), (0, 1, 2), "aan") for a in (1, 2): with suppress_logs('results.models', logging.WARNING): # suppress duplicate confirmed warning self._create_feedback(self._da(debate, 0), a) feedback2 = self._create_feedback(self._da(debate, 0), a) self.assertExpectedFromAdjudicatorTracker(debate, 0, a, True, True, 1, [feedback2])
def test_wbw_first(self): # tests wbw when it appears as the first metric generator = TeamStandingsGenerator(('wbw', ), ()) with suppress_logs('standings.teams', logging.INFO): standings = self.get_standings(generator) self.assertEqual(standings.get_standing(self.team1).metrics['wbw1'], 2) self.assertEqual(standings.get_standing(self.team2).metrics['wbw1'], 0)
def test_wbw_tied(self): # npullups should be 0 for both teams, so is a tied first metric, # allowing wbw to be tested as a second metric (the normal use case) generator = TeamStandingsGenerator(('npullups', 'wbw'), ()) with suppress_logs('standings.teams', logging.INFO): standings = self.get_standings(generator) self.assertEqual(standings.get_standing(self.team1).metrics['wbw1'], 2) self.assertEqual(standings.get_standing(self.team2).metrics['wbw1'], 0)
def test_draw_strength(self): generator = TeamStandingsGenerator(('draw_strength', ), ()) with suppress_logs('standings.teams', logging.INFO): standings = self.get_standings(generator) self.assertEqual( standings.get_standing(self.team1).metrics['draw_strength'], 0) # losing team has faced winning team twice, so draw strength is 2 * 2 = 4 self.assertEqual( standings.get_standing(self.team2).metrics['draw_strength'], 4)
def test_teamscore_field_votes_given(self, result, testdata, scoresheet_type): for side, votes in zip(self.SIDES, testdata[scoresheet_type]['num_adjs_for_team']): with suppress_logs('results.result', logging.WARNING): self.assertEqual(votes, self._get_teamscore_in_db(side).votes_given) self.assertEqual(votes, result.teamscore_field_votes_given(side))
def test_teamscore_field_score_everyone(self, result, testdata, scoresheet_type): for side, total in zip(self.SIDES, testdata['common']['everyone_totals']): with suppress_logs('results.result', logging.WARNING): self.assertAlmostEqual(total, self._get_teamscore_in_db(side).score) self.assertAlmostEqual(total, result.teamscore_field_score(side))
def test_teamscore_field_margin_everyone(self, result, testdata, scoresheet_type): for side, margin in zip(self.SIDES, testdata['common']['everyone_margins']): with suppress_logs('results.result', logging.WARNING): self.assertAlmostEqual(margin, self._get_teamscore_in_db(side).margin) self.assertAlmostEqual(margin, result.teamscore_field_margin(side))
def test_speaker_scores_everyone(self, result, testdata, scoresheet_type): for side, totals in zip(self.SIDES, testdata['common']['everyone_scores']): for pos, score in enumerate(totals, start=1): with suppress_logs('results.result', logging.WARNING): self.assertAlmostEqual( score, self._get_speakerscore_in_db(side, pos).score) self.assertAlmostEqual( score, result.speakerscore_field_score(side, pos))
def test_draw_strength_speaks(self): generator = TeamStandingsGenerator(('draw_strength_speaks', ), ()) with suppress_logs('standings.teams', logging.INFO): standings = self.get_standings(generator) # teams have faced each other twice, so draw strength is twice opponent's score self.assertEqual( standings.get_standing(self.team1).metrics['draw_strength_speaks'], 394) self.assertEqual( standings.get_standing(self.team2).metrics['draw_strength_speaks'], 406)
def test_initially_unknown_sides(self): self._unset_sides() testdata = self.testdata['high'] self.save_complete_result(testdata, post_create=lambda result: result.set_sides(*self.teams)) result = self.get_result() # Just check a couple of fields winner = testdata['high-required']['winner'] for side, margin in zip(self.SIDES, testdata['high-required']['majority_margins']): with suppress_logs('results.result', logging.WARNING): self.assertEqual(self._get_teamscore_in_db(side).win, side == winner) self.assertEqual(result.teamscorefield_win(side), side == winner) self.assertAlmostEqual(self._get_teamscore_in_db(side).margin, margin) self.assertAlmostEqual(result.teamscorefield_margin(side), margin)
def save_blank_result(self, nadjs=3, nspeakers=3): self.set_tournament_preference('debate_rules', 'substantive_speakers', nspeakers) # set debate adjudicators (depends on how many adjs there are, so can't do in setUp()) self.debate.adjudicators.chair = self.adjs[0] self.debate.adjudicators.panellists = self.adjs[1:nadjs] with suppress_logs('adjallocation.allocation', logging.INFO): self.debate.adjudicators.save() # unconfirm existing ballots self.debate.ballotsubmission_set.update(confirmed=False) ballotsub = BallotSubmission.objects.create(debate=self.debate, confirmed=True, submitter_type=BallotSubmission.SUBMITTER_TABROOM) return self.debate_result_class(ballotsub)
def run_test_for_error_response(self, expected_loglevel, error_type): url = self.reverse_round('draw-create') with self.assertLogs('draw.views', level=expected_loglevel) as cm, \ suppress_logs('standings.metrics', logging.INFO): response = self.client.post(url, follow=True) # Check that it logged something at the correct level (WARNING or ERROR), depending on the error self.assertEqual(cm.records[0].levelno, expected_loglevel) self.assertEqual(cm.records[0].exc_info[0], error_type) # Check that it redirects appropriately self.assertRedirects(response, self.reverse_round('availability-index')) # Check that there is a message at level ERROR messages = response.context.get('messages', []) self.assertEqual(len(messages), 1) message = list(messages)[0] self.assertEqual(message.level, ERROR)
def save_complete_result(self, testdata, post_create=None): nspeakers = testdata['num_speakers_per_team'] result = self.save_blank_result(nadjs=testdata['num_adjs'], nspeakers=nspeakers) if post_create: post_create(result) for side, team in zip(self.SIDES, self.teams): speakers = team.speaker_set.all()[0:nspeakers] for pos, speaker in enumerate(speakers, start=1): result.set_speaker(side, pos, speaker) result.set_speaker(side, nspeakers+1, speakers[0]) # ghost fields should be False by default self.save_scores_to_result(testdata, result) with suppress_logs('results.result', logging.WARNING): result.save()
def test_view_enabled(self): # Suppress standings queryset info logging with suppress_logs('standings.metrics', logging.INFO): super().test_view_enabled()
def test_unset_preference(self): with suppress_logs('standings.metrics', logging.INFO): super().test_unset_preference()
def get_standings(self, generator): with suppress_logs('standings.metrics', logging.INFO): standings = generator.generate(self.tournament.team_set.all()) return standings
def test_teamscorefield_votes_given(self, result, testdata, scoresheet_type): for side, votes in zip(self.SIDES, testdata[scoresheet_type]['num_adjs_for_team']): with suppress_logs('results.result', logging.WARNING): self.assertEqual(votes, self._get_teamscore_in_db(side).votes_given) self.assertEqual(votes, result.teamscorefield_votes_given(side))
def test_teamscorefield_margin_everyone(self, result, testdata, scoresheet_type): for side, margin in zip(self.SIDES, testdata['common']['everyone_margins']): with suppress_logs('results.result', logging.WARNING): self.assertAlmostEqual(margin, self._get_teamscore_in_db(side).margin) self.assertAlmostEqual(margin, result.teamscorefield_margin(side))
def test_teamscorefield_score_everyone(self, result, testdata, scoresheet_type): for side, total in zip(self.SIDES, testdata['common']['everyone_totals']): with suppress_logs('results.result', logging.WARNING): self.assertAlmostEqual(total, self._get_teamscore_in_db(side).score) self.assertAlmostEqual(total, result.teamscorefield_score(side))
def test_teamscorefield_win(self, result, testdata, scoresheet_type): for side in self.SIDES: win = side == testdata[scoresheet_type]['winner'] with suppress_logs('results.result', logging.WARNING): self.assertEqual(win, self._get_teamscore_in_db(side).win) self.assertEqual(win, result.teamscorefield_win(side))
def test_teamscorefield_points(self, result, testdata, scoresheet_type): for side in self.SIDES: points = 1 if side == testdata[scoresheet_type]['winner'] else 0 with suppress_logs('results.result', logging.WARNING): self.assertEqual(points, self._get_teamscore_in_db(side).points) self.assertEqual(points, result.teamscorefield_points(side))
def test_speaker_scores_everyone(self, result, testdata, scoresheet_type): for side, totals in zip(self.SIDES, testdata['common']['everyone_scores']): for pos, score in enumerate(totals, start=1): with suppress_logs('results.result', logging.WARNING): self.assertAlmostEqual(score, self._get_speakerscore_in_db(side, pos).score) self.assertAlmostEqual(score, result.get_speaker_score(side, pos))
def test_majority_adjudicators(self, result, testdata, scoresheet_type): majority = [self.adjs[i] for i in testdata[scoresheet_type]['majority_adjs']] with suppress_logs('results.result', logging.WARNING): self.assertCountEqual(majority, result.majority_adjudicators())
def test_set_preference(self): # Suppress standings queryset info logging with suppress_logs('standings.metrics', logging.INFO): super().test_set_preference()
def test_view_enabled(self): with suppress_logs('standings.metrics', logging.INFO): super().test_view_enabled()