本文整理匯總了Python中gomill.gtp_controller.Gtp_controller類的典型用法代碼示例。如果您正苦於以下問題:Python Gtp_controller類的具體用法?Python Gtp_controller怎麽用?Python Gtp_controller使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Gtp_controller類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_known_command
def test_known_command(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'kc test')
tc.assertTrue(controller.known_command("test"))
tc.assertFalse(controller.known_command("nonesuch"))
tc.assertTrue(controller.known_command("test"))
tc.assertFalse(controller.known_command("nonesuch"))
示例2: test_list_commands
def test_list_commands(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'lc test')
channel.engine.add_command("xyzzy", None)
channel.engine.add_command("pl ugh", None)
tc.assertListEqual(
controller.list_commands(),
['error', 'fatal', 'known_command', 'list_commands',
'multiline', 'protocol_version', 'quit', 'test', 'xyzzy'])
示例3: test_check_protocol_version_2
def test_check_protocol_version_2(tc):
channel = Preprogrammed_gtp_channel("= 1\n\n? error\n\n# unreached\n\n")
controller = Gtp_controller(channel, 'pv2 test')
with tc.assertRaises(BadGtpResponse) as ar:
controller.check_protocol_version()
tc.assertEqual(str(ar.exception), "pv2 test reports GTP protocol version 1")
tc.assertEqual(ar.exception.gtp_error_message, None)
# check error is not treated as a check failure
controller.check_protocol_version()
示例4: test_safe_do_command_closed_channel
def test_safe_do_command_closed_channel(tc):
# check it's ok to call safe_do_command() on a closed channel
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
controller.safe_close()
tc.assertIsNone(controller.safe_do_command("test"))
tc.assertListEqual(channel.engine.commands_handled,
[('quit', [])])
tc.assertListEqual(controller.retrieve_error_messages(), [])
示例5: test_controller_first_command_error
def test_controller_first_command_error(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
with tc.assertRaises(BadGtpResponse) as ar:
controller.do_command("error")
tc.assertEqual(
str(ar.exception),
"failure response from first command (error) to player test:\n"
"normal error")
tc.assertListEqual(controller.retrieve_error_messages(), [])
示例6: test_controller_close_error
def test_controller_close_error(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
channel.fail_close = True
with tc.assertRaises(GtpTransportError) as ar:
controller.close()
tc.assertEqual(
str(ar.exception),
"error closing player test:\n"
"forced failure for close")
tc.assertListEqual(controller.retrieve_error_messages(), [])
示例7: test_subprocess_channel_with_controller
def test_subprocess_channel_with_controller(tc):
# Also tests that leaving 'env' and 'cwd' unset works
fx = gtp_engine_fixtures.State_reporter_fixture(tc)
channel = gtp_controller.Subprocess_gtp_channel(fx.cmd, stderr=fx.devnull)
controller = Gtp_controller(channel, 'subprocess test')
tc.assertEqual(controller.do_command("tell"),
"cwd: %s\nGOMILL_TEST:None" % os.getcwd())
controller.close()
tc.assertEqual(channel.exit_status, 0)
rusage = channel.resource_usage
tc.assertTrue(hasattr(rusage, 'ru_utime'))
示例8: test_controller_safe_close_with_error_from_close
def test_controller_safe_close_with_error_from_close(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
channel.fail_close = True
controller.safe_close()
tc.assertTrue(controller.channel_is_closed)
tc.assertListEqual(channel.engine.commands_handled,
[('quit', [])])
tc.assertListEqual(
controller.retrieve_error_messages(),
["error closing player test:\n"
"forced failure for close"])
示例9: test_controller_safe_close_with_error_from_quit
def test_controller_safe_close_with_error_from_quit(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
channel.force_next_response = "# error\n\n"
controller.safe_close()
tc.assertTrue(controller.channel_is_closed)
tc.assertTrue(controller.channel.is_closed)
tc.assertListEqual(channel.engine.commands_handled,
[('quit', [])])
tc.assertListEqual(
controller.retrieve_error_messages(),
["GTP protocol error reading response to first command (quit) "
"from player test:\n"
"no success/failure indication from engine: first line is `# error`"])
示例10: test_controller_response_protocol_error
def test_controller_response_protocol_error(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
tc.assertEqual(controller.do_command("test"), "test response")
tc.assertFalse(controller.channel_is_bad)
channel.force_next_response = "# error\n\n"
with tc.assertRaises(GtpProtocolError) as ar:
controller.do_command("test")
tc.assertEqual(
str(ar.exception),
"GTP protocol error reading response to 'test' from player test:\n"
"no success/failure indication from engine: first line is `# error`")
tc.assertTrue(controller.channel_is_bad)
tc.assertListEqual(controller.retrieve_error_messages(), [])
示例11: test_controller_response_transport_error
def test_controller_response_transport_error(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
tc.assertFalse(controller.channel_is_bad)
channel.fail_next_response = True
with tc.assertRaises(GtpTransportError) as ar:
controller.do_command("test")
tc.assertEqual(
str(ar.exception),
"transport error reading response to first command (test) "
"from player test:\n"
"forced failure for get_response_line")
tc.assertTrue(controller.channel_is_bad)
tc.assertListEqual(controller.retrieve_error_messages(), [])
示例12: test_controller_close
def test_controller_close(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
tc.assertFalse(controller.channel_is_closed)
tc.assertEqual(controller.do_command("test"), "test response")
tc.assertFalse(controller.channel_is_closed)
tc.assertFalse(controller.channel.is_closed)
controller.close()
tc.assertTrue(controller.channel_is_closed)
tc.assertTrue(controller.channel.is_closed)
tc.assertRaisesRegexp(StandardError, "^channel is closed$",
controller.do_command, "test")
tc.assertRaisesRegexp(StandardError, "^channel is closed$",
controller.close)
tc.assertListEqual(controller.retrieve_error_messages(), [])
示例13: test_controller_safe_close_with_failure_response_from_quit
def test_controller_safe_close_with_failure_response_from_quit(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
channel.engine.force_error("quit")
controller.safe_close()
tc.assertTrue(controller.channel_is_closed)
tc.assertTrue(controller.channel.is_closed)
tc.assertListEqual(channel.engine.commands_handled,
[('quit', [])])
error_messages = controller.retrieve_error_messages()
tc.assertEqual(len(error_messages), 1)
tc.assertEqual(
error_messages[0],
"failure response from first command (quit) to player test:\n"
"handler forced to fail")
示例14: test_controller_alt_exit
def test_controller_alt_exit(tc):
channel = gtp_engine_fixtures.get_test_channel()
channel.engine_exit_breaks_commands = False
controller = Gtp_controller(channel, 'player test')
controller.do_command("quit")
tc.assertFalse(controller.channel_is_bad)
with tc.assertRaises(GtpChannelClosed) as ar:
controller.do_command("test")
tc.assertEqual(str(ar.exception),
"error reading response to 'test' from player test:\n"
"engine has closed the response channel")
tc.assertTrue(controller.channel_is_bad)
controller.close()
tc.assertListEqual(controller.retrieve_error_messages(), [])
示例15: test_safe_do_command
def test_safe_do_command(tc):
channel = gtp_engine_fixtures.get_test_channel()
controller = Gtp_controller(channel, 'player test')
tc.assertEqual(controller.safe_do_command("test", "ab"), "args: ab")
with tc.assertRaises(BadGtpResponse) as ar:
controller.safe_do_command("error")
tc.assertFalse(controller.channel_is_bad)
channel.fail_next_response = True
tc.assertIsNone(controller.safe_do_command("test"))
tc.assertTrue(controller.channel_is_bad)
tc.assertIsNone(controller.safe_do_command("test"))
tc.assertListEqual(
controller.retrieve_error_messages(),
["transport error reading response to 'test' from player test:\n"
"forced failure for get_response_line"])
controller.safe_close()
# check that third 'test' wasn't sent, and nor was 'quit'
tc.assertListEqual(channel.engine.commands_handled,
[('test', ['ab']), ('error', []), ('test', [])])