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(), [])
def test_gtp_aliases_safe(tc): channel = gtp_engine_fixtures.get_test_channel() controller = Gtp_controller(channel, 'alias test') controller.set_gtp_aliases({ 'aliased': 'test', 'aliased2': 'nonesuch', }) tc.assertIs(controller.safe_known_command("test"), True) tc.assertIs(controller.safe_known_command("aliased"), True) tc.assertIs(controller.safe_known_command("nonesuch"), False) tc.assertIs(controller.safe_known_command("test"), True) tc.assertIs(controller.safe_known_command("aliased"), True) tc.assertIs(controller.safe_known_command("nonesuch"), False) tc.assertEqual(controller.safe_do_command("test"), "test response") tc.assertEqual(controller.safe_do_command("aliased"), "test response") with tc.assertRaises(BadGtpResponse) as ar: controller.safe_do_command("aliased2") tc.assertEqual(ar.exception.gtp_error_message, "unknown command") tc.assertEqual(ar.exception.gtp_command, "nonesuch")
def test_gtp_aliases_safe(tc): channel = gtp_engine_fixtures.get_test_channel() controller = Gtp_controller(channel, 'alias test') controller.set_gtp_aliases({ 'aliased' : 'test', 'aliased2' : 'nonesuch', }) tc.assertIs(controller.safe_known_command("test"), True) tc.assertIs(controller.safe_known_command("aliased"), True) tc.assertIs(controller.safe_known_command("nonesuch"), False) tc.assertIs(controller.safe_known_command("test"), True) tc.assertIs(controller.safe_known_command("aliased"), True) tc.assertIs(controller.safe_known_command("nonesuch"), False) tc.assertEqual(controller.safe_do_command("test"), "test response") tc.assertEqual(controller.safe_do_command("aliased"), "test response") with tc.assertRaises(BadGtpResponse) as ar: controller.safe_do_command("aliased2") tc.assertEqual(ar.exception.gtp_error_message, "unknown command") tc.assertEqual(ar.exception.gtp_command, "nonesuch")
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', [])])
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', [])])