def test_controller(tc): channel = gtp_engine_fixtures.get_test_channel() controller = Gtp_controller(channel, 'player test') tc.assertEqual(controller.name, 'player test') tc.assertIs(controller.channel, channel) tc.assertFalse(controller.channel_is_bad) tc.assertEqual(controller.do_command("test", "ab", "cd"), "args: ab cd") with tc.assertRaises(BadGtpResponse) as ar: controller.do_command("error") tc.assertEqual(ar.exception.gtp_error_message, "normal error") tc.assertEqual(ar.exception.gtp_command, "error") tc.assertSequenceEqual(ar.exception.gtp_arguments, []) tc.assertEqual( str(ar.exception), "failure response from 'error' to player test:\n" "normal error") with tc.assertRaises(BadGtpResponse) as ar: controller.do_command("fatal") tc.assertFalse(controller.channel_is_bad) with tc.assertRaises(GtpChannelClosed) as ar: controller.do_command("test") tc.assertEqual( str(ar.exception), "error sending 'test' to player test:\n" "engine has closed the command channel") tc.assertTrue(controller.channel_is_bad) controller.close() tc.assertListEqual(controller.retrieve_error_messages(), [])
def test_controller(tc): channel = gtp_engine_fixtures.get_test_channel() controller = Gtp_controller(channel, 'player test') tc.assertEqual(controller.name, 'player test') tc.assertIs(controller.channel, channel) tc.assertFalse(controller.channel_is_bad) tc.assertEqual(controller.do_command("test", "ab", "cd"), "args: ab cd") with tc.assertRaises(BadGtpResponse) as ar: controller.do_command("error") tc.assertEqual(ar.exception.gtp_error_message, "normal error") tc.assertEqual(ar.exception.gtp_command, "error") tc.assertSequenceEqual(ar.exception.gtp_arguments, []) tc.assertEqual(str(ar.exception), "failure response from 'error' to player test:\n" "normal error") with tc.assertRaises(BadGtpResponse) as ar: controller.do_command("fatal") tc.assertFalse(controller.channel_is_bad) with tc.assertRaises(GtpChannelClosed) as ar: controller.do_command("test") tc.assertEqual(str(ar.exception), "error sending 'test' to player test:\n" "engine has closed the command channel") tc.assertTrue(controller.channel_is_bad) controller.close() tc.assertListEqual(controller.retrieve_error_messages(), [])
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(), [])
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'))
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(), [])
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(), [])
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(), [])
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(), [])