Ejemplo n.º 1
0
def test_set_back_end_subprocess(tc):
    fx = gtp_engine_fixtures.State_reporter_fixture(tc)
    proxy = gtp_proxy.Gtp_proxy()
    # the state-report will be taken as the response to list_commands
    proxy.set_back_end_subprocess(fx.cmd, stderr=fx.devnull)
    proxy.expect_back_end_exit()
    proxy.close()
Ejemplo n.º 2
0
def main(executable):
    try:
        if sys.argv[1] not in ("--9", "--13", "--19"):
            raise ValueError
        size = sys.argv[1][2:]
    except Exception:
        sys.exit("mogo_wrapper: first parameter must be --9, --13, or --19")

    def handle_boardsize(args):
        # No need to pass this down to mogo.
        try:
            if args[0] != size:
                raise gtp_engine.GtpError("board size %s only please" % size)
        except IndexError:
            gtp_engine.report_bad_arguments()

    proxy = gtp_proxy.Gtp_proxy()
    proxy.set_back_end_subprocess([executable] + sys.argv[1:])
    proxy.engine.add_command("version", handle_version)
    proxy.engine.add_command("boardsize", handle_boardsize)
    proxy.pass_command("boardsize", [size])
    try:
        proxy.run()
    except KeyboardInterrupt:
        sys.exit(1)
Ejemplo n.º 3
0
 def __init__(self, tc):
     self.tc = tc
     self.channel = gtp_engine_fixtures.get_test_channel()
     self.underlying_engine = self.channel.engine
     self.controller = gtp_controller.Gtp_controller(
         self.channel, 'testbackend')
     self.proxy = gtp_proxy.Gtp_proxy()
     self.proxy.set_back_end_controller(self.controller)
     self.engine = self.proxy.engine
     self.commands_handled = self.underlying_engine.commands_handled
Ejemplo n.º 4
0
def test_set_back_end_subprocess_nonexistent_program(tc):
    proxy = gtp_proxy.Gtp_proxy()
    with tc.assertRaises(BackEndError) as ar:
        proxy.set_back_end_subprocess("/nonexistent/program")
    tc.assertEqual(
        str(ar.exception), "can't launch back end command\n"
        "[Errno 2] No such file or directory")
    tc.assertIsInstance(ar.exception.cause, GtpChannelError)
    # check it's safe to close when the controller was never set
    proxy.close()
Ejemplo n.º 5
0
def test_error_from_list_commands(tc):
    channel = gtp_engine_fixtures.get_test_channel()
    channel.engine.force_error("list_commands")
    controller = gtp_controller.Gtp_controller(channel, 'testbackend')
    proxy = gtp_proxy.Gtp_proxy()
    with tc.assertRaises(BackEndError) as ar:
        proxy.set_back_end_controller(controller)
    tc.assertEqual(
        str(ar.exception), "failure response from first command "
        "(list_commands) to testbackend:\n"
        "handler forced to fail")
    tc.assertIsInstance(ar.exception.cause, BadGtpResponse)
    proxy.close()
def test_nontgtp_backend(tc):
    channel = gtp_controller_test_support.Preprogrammed_gtp_channel(
        "Usage: randomprogram [options]\n\nOptions:\n"
        "--help   show this help message and exit\n")
    controller = gtp_controller.Gtp_controller(channel, 'testbackend')
    proxy = gtp_proxy.Gtp_proxy()
    with tc.assertRaises(BackEndError) as ar:
        proxy.set_back_end_controller(controller)
    tc.assertEqual(str(ar.exception),
                   "GTP protocol error reading response to first command "
                   "(list_commands) from testbackend:\n"
                   "engine isn't speaking GTP: first byte is 'U'")
    tc.assertIsInstance(ar.exception.cause, GtpProtocolError)
    proxy.close()
Ejemplo n.º 7
0
    def run(self):
        self.proxy = gtp_proxy.Gtp_proxy()
        try:
            self.proxy.set_back_end_subprocess(self.subprocess_command)
            self.proxy.engine.add_commands({
                'genmove':
                self.handle_genmove,
                'kgs-game_over':
                self.handle_game_over,
            })
            if (self.do_savesgf
                    and not self.proxy.back_end_has_command("gomill-savesgf")):
                sys.exit("kgs_proxy: back end doesn't support gomill-savesgf")

            # Colour that we appear to be playing
            self.my_colour = None
            self.initialise_name()
        except gtp_proxy.BackEndError, e:
            sys.exit("kgs_proxy: %s" % e)