def test_game_job_worker_id(tc): fx = gtp_engine_fixtures.Mock_subprocess_fixture(tc) gj = Game_job_fixture(tc) result = gj.job.run(0) channel = fx.get_channel('one') tc.assertEqual(channel.requested_env['GOMILL_GAME_ID'], 'gameid') tc.assertEqual(channel.requested_env['GOMILL_SLOT'], '0')
def test_game_controller_set_player_subprocess(tc): msf = gtp_engine_fixtures.Mock_subprocess_fixture(tc) engine = gtp_engine_fixtures.get_test_engine() engine.add_command("name", lambda args: 'blackplayer') msf.register_engine('named', engine) gc = gtp_controller.Game_controller('one', 'two') gc.set_player_subprocess('b', ['testb', 'id=one', 'engine=named'], check_protocol_version=False) gc.set_player_subprocess('w', ['testw', 'id=two'], env={'a': 'b'}) tc.assertEqual(gc.get_controller('b').name, "player one") tc.assertEqual(gc.get_controller('w').name, "player two") tc.assertEqual(gc.engine_descriptions['b'].raw_name, "blackplayer") tc.assertIsNone(gc.engine_descriptions['w'].raw_name) channel1 = msf.get_channel('one') channel2 = msf.get_channel('two') tc.assertEqual(channel1.engine.commands_handled[0][0], 'name') tc.assertIsNone(channel1.requested_env) tc.assertEqual(channel2.engine.commands_handled[0][0], 'protocol_version') tc.assertEqual(channel2.requested_env, {'a': 'b'}) gc.close_players() tc.assertEqual(gc.get_resource_usage_cpu_times(), {'b': 546.2, 'w': 567.2})
def __init__(self, tc, control_file_contents, extra_lines=[]): self.ringmaster = ringmaster_test_support.Testing_ringmaster( control_file_contents + "\n".join(extra_lines)) self.ringmaster.set_display_mode('test') self.msf = gtp_engine_fixtures.Mock_subprocess_fixture(tc) self.msf.register_init_callback('p1', lambda x: None) self.msf.register_init_callback('p2', lambda x: None)
def test_game_controller_set_player_subprocess_error(tc): msf = gtp_engine_fixtures.Mock_subprocess_fixture(tc) gc = gtp_controller.Game_controller('one', 'two') with tc.assertRaises(GtpChannelError) as ar: gc.set_player_subprocess('b', ['testb', 'fail=startup']) tc.assertEqual( str(ar.exception), "error starting subprocess for player one:\nexec forced to fail") tc.assertRaises(KeyError, gc.get_controller, 'b') tc.assertEqual(gc.get_resource_usage_cpu_times(), {'b': None, 'w': None})