def check_screen_report(self, expected): """Check that the screen report is as expected.""" check_screen_report(self.tc, self.comp, expected)
def test_matchup_reappearance(tc): # Test that if a matchup is removed and added again, we remember the game # number. Test that we report the 'ghost' matchup in the short report (but # not the screen report). config1 = default_config() config1['matchups'].append(Matchup_config('t2', 't1')) config2 = default_config() config3 = default_config() config3['matchups'].append(Matchup_config('t2', 't1')) comp1 = playoffs.Playoff('testcomp') comp1.initialise_from_control_file(config1) comp1.set_clean_status() jobs1 = [comp1.get_game() for _ in range(8)] for job in jobs1: comp1.process_game_result(fake_response(job, 'b')) tc.assertListEqual( [job.game_id for job in jobs1], ['0_0', '1_0', '0_1', '1_1', '0_2', '1_2', '0_3', '1_3']) expected_matchups_1 = dedent("""\ t1 v t2 (4 games) board size: 13 komi: 7.5 wins black white t1 2 50.00% 2 100.00% 0 0.00% t2 2 50.00% 2 100.00% 0 0.00% 4 100.00% 0 0.00% t2 v t1 (4 games) board size: 13 komi: 7.5 wins t2 4 100.00% (black) t1 0 0.00% (white) """) check_screen_report(tc, comp1, expected_matchups_1) check_short_report(tc, comp1, expected_matchups_1, expected_fake_players) comp2 = playoffs.Playoff('testcomp') comp2.initialise_from_control_file(config2) comp2.set_status(pickle.loads(pickle.dumps(comp1.get_status()))) jobs2 = [comp2.get_game() for _ in range(4)] tc.assertListEqual( [job.game_id for job in jobs2], ['0_4', '0_5', '0_6', '0_7']) for job in jobs2: comp2.process_game_result(fake_response(job, 'b')) expected_matchups_2 = dedent("""\ t1 v t2 (8 games) board size: 13 komi: 7.5 wins black white t1 4 50.00% 4 100.00% 0 0.00% t2 4 50.00% 4 100.00% 0 0.00% 8 100.00% 0 0.00% """) check_screen_report(tc, comp2, expected_matchups_2) expected_matchups_2b = dedent("""\ t2 v t1 (4 games) ?? (missing from control file) wins t2 4 100.00% (black) t1 0 0.00% (white) """) check_short_report( tc, comp2, expected_matchups_2 + "\n" + expected_matchups_2b, expected_fake_players) comp3 = playoffs.Playoff('testcomp') comp3.initialise_from_control_file(config3) comp3.set_status(pickle.loads(pickle.dumps(comp2.get_status()))) jobs3 = [comp3.get_game() for _ in range(8)] tc.assertListEqual( [job.game_id for job in jobs3], ['1_4', '1_5', '1_6', '1_7', '0_8', '1_8', '0_9', '1_9']) expected_matchups_3 = dedent("""\ t1 v t2 (8 games) board size: 13 komi: 7.5 wins black white t1 4 50.00% 4 100.00% 0 0.00% t2 4 50.00% 4 100.00% 0 0.00% 8 100.00% 0 0.00% t2 v t1 (4 games) board size: 13 komi: 7.5 wins t2 4 100.00% (black) t1 0 0.00% (white) """) check_screen_report(tc, comp3, expected_matchups_3) check_short_report(tc, comp3, expected_matchups_3, expected_fake_players)