def test_check_player_nonexistent_cwd(tc): fx = Player_check_fixture(tc) fx.player.cwd = "/nonexistent/directory" with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(fx.check) tc.assertEqual(str(ar.exception), "bad working directory: /nonexistent/directory")
def test_check_player_nonexistent_cwd(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) ck = Player_check_fixture(tc) ck.player.cwd = "/nonexistent/directory" with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(ck.check) tc.assertEqual(str(ar.exception), "bad working directory: /nonexistent/directory")
def test_check_player_exec_failure(tc): fx = Player_check_fixture(tc) fx.player.cmd_args.append('fail=startup') with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(fx.check) tc.assertEqual(str(ar.exception), "error starting subprocess for test:\n" "exec forced to fail")
def test_check_player_exec_failure(tc): fx = Player_check_fixture(tc) fx.player.cmd_args.append('fail=startup') with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(fx.check) tc.assertEqual( str(ar.exception), "error starting subprocess for test:\n" "exec forced to fail")
def test_check_player_startup_gtp_commands(tc): fx = Player_check_fixture(tc) fx.player.startup_gtp_commands = [('list_commands', []), ('nonexistent', ['command'])] with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(fx.check) tc.assertEqual(str(ar.exception), "failure response from 'nonexistent command' to test:\n" "unknown command")
def test_check_player_boardsize_fails(tc): engine = gtp_engine_fixtures.get_test_engine() fx = Player_check_fixture(tc) fx.register_engine('no_boardsize', engine) fx.player.cmd_args.append('engine=no_boardsize') with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(fx.check) tc.assertEqual( str(ar.exception), "failure response from 'boardsize 9' to test:\n" "unknown command")
def test_check_player_boardsize_fails(tc): engine = gtp_engine_fixtures.get_test_engine() fx = Player_check_fixture(tc) fx.register_engine('no_boardsize', engine) fx.player.cmd_args.append('engine=no_boardsize') with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(fx.check) tc.assertEqual(str(ar.exception), "failure response from 'boardsize 9' to test:\n" "unknown command")
def test_check_player_channel_error(tc): def fail_first_command(channel): channel.fail_next_command = True fx = Player_check_fixture(tc) fx.register_init_callback('fail_first_command', fail_first_command) fx.player.cmd_args.append('init=fail_first_command') with tc.assertRaises(game_jobs.CheckFailed) as ar: game_jobs.check_player(fx.check) tc.assertEqual(str(ar.exception), "transport error sending first command (protocol_version) " "to test:\n" "forced failure for send_command_line")
def test_check_player_cwd(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) ck = Player_check_fixture(tc) ck.player.cwd = "/" tc.assertEqual(game_jobs.check_player(ck.check), []) channel = fx.get_channel('test') tc.assertEqual(channel.requested_cwd, "/")
def test_check_player_discard_stderr(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) ck = Player_check_fixture(tc) tc.assertEqual(game_jobs.check_player(ck.check, discard_stderr=True), []) channel = fx.get_channel('test') tc.assertIsInstance(channel.requested_stderr, file) tc.assertEqual(channel.requested_stderr.name, os.devnull)
def test_check_player_channel_error_on_close(tc): def fail_close(channel): channel.fail_close = True fx = Player_check_fixture(tc) fx.register_init_callback('fail_close', fail_close) fx.player.cmd_args.append('init=fail_close') tc.assertEqual(game_jobs.check_player(fx.check), ["error closing test:\nforced failure for close"])
def test_check_player(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) ck = Player_check_fixture(tc) tc.assertEqual(game_jobs.check_player(ck.check), []) channel = fx.get_channel('test') tc.assertIsNone(channel.requested_stderr) tc.assertIsNone(channel.requested_cwd) tc.assertIsNone(channel.requested_env)
def test_check_player(tc): fx = Player_check_fixture(tc) tc.assertEqual(game_jobs.check_player(fx.check), []) channel = fx.get_channel('test') tc.assertIsNone(channel.requested_stderr) tc.assertIsNone(channel.requested_cwd) tc.assertIn('PATH', channel.requested_env) tc.assertEqual(channel.requested_env['GOMILL_GAME_ID'], 'startup-check')
def test_check_player_env(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) ck = Player_check_fixture(tc) ck.player.environ = {'GOMILL_TEST' : 'gomill'} tc.assertEqual(game_jobs.check_player(ck.check), []) channel = fx.get_channel('test') tc.assertEqual(channel.requested_env['GOMILL_TEST'], 'gomill') # Check environment was merged, not replaced tc.assertIn('PATH', channel.requested_env)
def test_check_player_env(tc): fx = Player_check_fixture(tc) fx.player.environ = {'GOMILL_TEST': 'gomill'} tc.assertEqual(game_jobs.check_player(fx.check), []) channel = fx.get_channel('test') tc.assertEqual(channel.requested_env['GOMILL_TEST'], 'gomill') tc.assertNotIn('GOMILL_SLOT', channel.requested_env) # Check environment was merged, not replaced tc.assertEqual(channel.requested_env['GOMILL_GAME_ID'], 'startup-check') tc.assertIn('PATH', channel.requested_env)
def test_check_player_env(tc): fx = Player_check_fixture(tc) fx.player.environ = {'GOMILL_TEST' : 'gomill'} tc.assertEqual(game_jobs.check_player(fx.check), []) channel = fx.get_channel('test') tc.assertEqual(channel.requested_env['GOMILL_TEST'], 'gomill') tc.assertNotIn('GOMILL_SLOT', channel.requested_env) # Check environment was merged, not replaced tc.assertEqual(channel.requested_env['GOMILL_GAME_ID'], 'startup-check') tc.assertIn('PATH', channel.requested_env)
def test_check_player_cwd(tc): fx = Player_check_fixture(tc) fx.player.cwd = "/" tc.assertEqual(game_jobs.check_player(fx.check), []) channel = fx.get_channel('test') tc.assertEqual(channel.requested_cwd, "/")
def test_check_player_discard_stderr(tc): fx = Player_check_fixture(tc) tc.assertEqual(game_jobs.check_player(fx.check, discard_stderr=True), []) channel = fx.get_channel('test') tc.assertIsInstance(channel.requested_stderr, file) tc.assertEqual(channel.requested_stderr.name, os.devnull)
except EnvironmentError, e: print >> sys.stderr, e def check_players(self, discard_stderr=False): """Check that the engines required for the competition will run. If an engine fails, prints a description of the problem and returns False without continuing to check. Otherwise returns True. """ try: to_check = self.competition.get_player_checks() except CompetitionError, e: raise RingmasterError(e) for check in to_check: if not discard_stderr: print "checking player %s" % check.player.code try: msgs = game_jobs.check_player(check, discard_stderr) except game_jobs.CheckFailed, e: print "player %s failed startup check:\n%s" % ( check.player.code, e) return False else: if not discard_stderr: for msg in msgs: print msg return True
print >>sys.stderr, e def check_players(self, discard_stderr=False): """Check that the engines required for the competition will run. If an engine fails, prints a description of the problem and returns False without continuing to check. Otherwise returns True. """ try: to_check = self.competition.get_player_checks() except CompetitionError, e: raise RingmasterError(e) for check in to_check: if not discard_stderr: print "checking player %s" % check.player.code try: msgs = game_jobs.check_player(check, discard_stderr) except game_jobs.CheckFailed, e: print "player %s failed startup check:\n%s" % ( check.player.code, e) return False else: if not discard_stderr: for msg in msgs: print msg return True