Esempio n. 1
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})
Esempio n. 2
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})
Esempio n. 3
0
def test_testing_gtp_channel_sequencing(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    tc.assertRaisesRegexp(SupporterError, "response request without command",
                          channel.get_response)
    channel.send_command("test", [])
    tc.assertRaisesRegexp(SupporterError, "two commands in a row",
                          channel.send_command, "test", [])
Esempio n. 4
0
def test_testing_gtp_channel_fatal_errors(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.send_command("fatal", [])
    tc.assertEqual(channel.get_response(), (True, "fatal error"))
    tc.assertRaisesRegexp(GtpChannelClosed,
                          "engine has closed the response channel",
                          channel.get_response)
    channel.close()
Esempio n. 5
0
def test_testing_gtp_channel_fatal_errors(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.send_command("fatal", [])
    tc.assertEqual(channel.get_response(), (True, "fatal error"))
    tc.assertRaisesRegexp(
        GtpChannelClosed, "engine has closed the response channel",
        channel.get_response)
    channel.close()
Esempio n. 6
0
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")
Esempio n. 7
0
def test_testing_gtp_channel_sequencing(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    tc.assertRaisesRegexp(
        SupporterError, "response request without command",
        channel.get_response)
    channel.send_command("test", [])
    tc.assertRaisesRegexp(
        SupporterError, "two commands in a row",
        channel.send_command, "test", [])
Esempio n. 8
0
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")
Esempio n. 9
0
def test_testing_gtp_channel_alt(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.engine_exit_breaks_commands = False
    channel.send_command("test", [])
    tc.assertEqual(channel.get_response(), (False, "test response"))
    channel.send_command("quit", [])
    tc.assertEqual(channel.get_response(), (False, ""))
    channel.send_command("test", [])
    tc.assertRaisesRegexp(GtpChannelClosed,
                          "engine has closed the response channel",
                          channel.get_response)
    channel.close()
Esempio n. 10
0
def test_testing_gtp_channel_alt(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.engine_exit_breaks_commands = False
    channel.send_command("test", [])
    tc.assertEqual(channel.get_response(), (False, "test response"))
    channel.send_command("quit", [])
    tc.assertEqual(channel.get_response(), (False, ""))
    channel.send_command("test", [])
    tc.assertRaisesRegexp(
        GtpChannelClosed, "engine has closed the response channel",
        channel.get_response)
    channel.close()
Esempio n. 11
0
def test_testing_gtp_channel(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.send_command("play", ["b", "a3"])
    tc.assertEqual(channel.get_response(), (True, "unknown command"))
    channel.send_command("test", [])
    tc.assertEqual(channel.get_response(), (False, "test response"))
    channel.send_command("multiline", [])
    tc.assertEqual(channel.get_response(),
                   (False, "first line  \n  second line\nthird line"))
    channel.send_command("quit", [])
    tc.assertEqual(channel.get_response(), (False, ""))
    tc.assertRaisesRegexp(GtpChannelClosed,
                          "engine has closed the command channel",
                          channel.send_command, "quit", [])
    channel.close()
Esempio n. 12
0
def test_testing_gtp_channel(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.send_command("play", ["b", "a3"])
    tc.assertEqual(channel.get_response(), (True, "unknown command"))
    channel.send_command("test", [])
    tc.assertEqual(channel.get_response(), (False, "test response"))
    channel.send_command("multiline", [])
    tc.assertEqual(channel.get_response(),
                   (False, "first line  \n  second line\nthird line"))
    channel.send_command("quit", [])
    tc.assertEqual(channel.get_response(), (False, ""))
    tc.assertRaisesRegexp(
        GtpChannelClosed, "engine has closed the command channel",
        channel.send_command, "quit", [])
    channel.close()
Esempio n. 13
0
def test_testing_gtp_force_error(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.fail_next_command = True
    tc.assertRaisesRegexp(GtpTransportError,
                          "forced failure for send_command_line",
                          channel.send_command, "test", [])
    channel.send_command("test", [])
    channel.fail_next_response = True
    tc.assertRaisesRegexp(GtpTransportError,
                          "forced failure for get_response_line",
                          channel.get_response)
    channel.force_next_response = "# error\n\n"
    tc.assertRaisesRegexp(
        GtpProtocolError,
        "no success/failure indication from engine: first line is `# error`",
        channel.get_response)
    channel.fail_close = True
    tc.assertRaisesRegexp(GtpTransportError, "forced failure for close",
                          channel.close)
Esempio n. 14
0
def test_testing_gtp_force_error(tc):
    engine = gtp_engine_fixtures.get_test_engine()
    channel = gtp_controller_test_support.Testing_gtp_channel(engine)
    channel.fail_next_command = True
    tc.assertRaisesRegexp(
        GtpTransportError, "forced failure for send_command_line",
        channel.send_command, "test", [])
    channel.send_command("test", [])
    channel.fail_next_response = True
    tc.assertRaisesRegexp(
        GtpTransportError, "forced failure for get_response_line",
        channel.get_response)
    channel.force_next_response = "# error\n\n"
    tc.assertRaisesRegexp(
        GtpProtocolError,
        "no success/failure indication from engine: first line is `# error`",
        channel.get_response)
    channel.fail_close = True
    tc.assertRaisesRegexp(
        GtpTransportError, "forced failure for close",
        channel.close)