def test_linebased_channel(tc): channel = Preprogrammed_gtp_channel("=\n\n=\n\n") tc.assertEqual(channel.get_command_stream(), "") channel.send_command("play", ["b", "a3"]) tc.assertEqual(channel.get_command_stream(), "play b a3\n") tc.assertEqual(channel.get_response(), (False, "")) channel.send_command("quit", []) tc.assertEqual(channel.get_command_stream(), "play b a3\nquit\n") tc.assertEqual(channel.get_response(), (False, "")) tc.assertRaisesRegexp(GtpChannelClosed, "engine has closed the response channel", channel.get_response) channel.close()
def test_linebased_channel(tc): channel = Preprogrammed_gtp_channel("=\n\n=\n\n") tc.assertEqual(channel.get_command_stream(), "") channel.send_command("play", ["b", "a3"]) tc.assertEqual(channel.get_command_stream(), "play b a3\n") tc.assertEqual(channel.get_response(), (False, "")) channel.send_command("quit", []) tc.assertEqual(channel.get_command_stream(), "play b a3\nquit\n") tc.assertEqual(channel.get_response(), (False, "")) tc.assertRaisesRegexp( GtpChannelClosed, "engine has closed the response channel", channel.get_response) channel.close()
def test_known_command_2(tc): # Checking that known_command caches its responses # and that it treats an error or unknown value the same as 'false'. channel = Preprogrammed_gtp_channel( "= true\n\n= absolutely not\n\n? error\n\n# unreached\n\n") controller = Gtp_controller(channel, 'kc2 test') tc.assertTrue(controller.known_command("one")) tc.assertFalse(controller.known_command("two")) tc.assertFalse(controller.known_command("three")) tc.assertTrue(controller.known_command("one")) tc.assertFalse(controller.known_command("two")) tc.assertEqual( channel.get_command_stream(), "known_command one\nknown_command two\nknown_command three\n")
def test_known_command_2(tc): # Checking that known_command caches its responses # and that it treats an error or unknown value the same as 'false'. channel = Preprogrammed_gtp_channel( "= true\n\n= absolutely not\n\n? error\n\n# unreached\n\n") controller = Gtp_controller(channel, 'kc2 test') tc.assertTrue(controller.known_command("one")) tc.assertFalse(controller.known_command("two")) tc.assertFalse(controller.known_command("three")) tc.assertTrue(controller.known_command("one")) tc.assertFalse(controller.known_command("two")) tc.assertEqual( channel.get_command_stream(), "known_command one\nknown_command two\nknown_command three\n")
def test_channel_command_validation(tc): channel = Preprogrammed_gtp_channel("\n\n") # empty command tc.assertRaises(ValueError, channel.send_command, "", []) # space in command tc.assertRaises(ValueError, channel.send_command, "play b a3", []) # space after command tc.assertRaises(ValueError, channel.send_command, "play ", ["b", "a3"]) # control character in command tc.assertRaises(ValueError, channel.send_command, "pla\x01y", ["b", "a3"]) # unicode command tc.assertRaises(ValueError, channel.send_command, u"protocol_version", []) # space in argument tc.assertRaises(ValueError, channel.send_command, "play", ["b a3"]) # unicode argument tc.assertRaises(ValueError, channel.send_command, "play ", [u"b", "a3"]) # high characters channel.send_command("pl\xc3\xa1y", ["b", "\xc3\xa13"]) tc.assertEqual(channel.get_command_stream(), "pl\xc3\xa1y b \xc3\xa13\n")
def test_channel_command_validation(tc): channel = Preprogrammed_gtp_channel("\n\n") # empty command tc.assertRaises(ValueError, channel.send_command, "", []) # space in command tc.assertRaises(ValueError, channel.send_command, "play b a3", []) # space after command tc.assertRaises(ValueError, channel.send_command, "play ", ["b", "a3"]) # control character in command tc.assertRaises(ValueError, channel.send_command, "pla\x01y", ["b", "a3"]) # unicode command tc.assertRaises(ValueError, channel.send_command, u"protocol_version", []) # space in argument tc.assertRaises(ValueError, channel.send_command, "play", ["b a3"]) # unicode argument tc.assertRaises(ValueError, channel.send_command, "play ", [u"b", "a3"]) # high characters channel.send_command("pl\xc3\xa1y", ["b", "\xc3\xa13"]) tc.assertEqual(channel.get_command_stream(), "pl\xc3\xa1y b \xc3\xa13\n")