class ProtocolTest(unittest.TestCase): def tearDown(self): # Safety check in case there was an exception... safe_shutdown(self) def testEscape(self): self.assertEqual( "Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\"))) self.assertEqual( "Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\"))) def testProtocolSend(self): testConnection = TestConnection() self.gateway = JavaGateway(testConnection, False) e = self.gateway.getExample() self.assertEqual('c\nt\ngetExample\ne\n', testConnection.last_message) e.method1(1, True, 'Hello\nWorld', e, None, 1.5) self.assertEqual( 'c\no0\nmethod1\ni1\nbTrue\nsHello\\nWorld\nro0\nn\nd1.5\ne\n', testConnection.last_message) del (e) def testProtocolReceive(self): p = start_echo_server_process() time.sleep(1) try: testSocket = get_socket() testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('yro0\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('ysHello World\n'.encode('utf-8')) # No extra echange (method3) because it is already cached. testSocket.sendall('yi123\n'.encode('utf-8')) testSocket.sendall('yd1.25\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('yn\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('ybTrue\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('yL123\n'.encode('utf-8')) testSocket.close() time.sleep(1) self.gateway = JavaGateway(auto_field=True) ex = self.gateway.getNewExample() self.assertEqual('Hello World', ex.method3(1, True)) self.assertEqual(123, ex.method3()) self.assertAlmostEqual(1.25, ex.method3()) self.assertIsNone(ex.method2()) self.assertTrue(ex.method4()) self.assertEqual(long(123), ex.method8()) self.gateway.shutdown() except Exception as e: print('Error has occurred', e) print_exc() self.fail('Problem occurred') p.join()
def testProtocolSend(self): testConnection = TestConnection() gateway = JavaGateway(testConnection, False) e = gateway.getExample() self.assertEqual('c\nt\ngetExample\ne\n', testConnection.last_message) e.method1(1, True, 'Hello\nWorld', e, None, 1.5) self.assertEqual('c\no0\nmethod1\ni1\nbTrue\nsHello\\nWorld\nro0\nn\nd1.5\ne\n', testConnection.last_message) del(e)
class ProtocolTest(unittest.TestCase): def tearDown(self): # Safety check in case there was an exception... safe_shutdown(self) def testEscape(self): self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line( escape_new_line("Hello\t\rWorld\n\\"))) self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line( escape_new_line("Hello\t\rWorld\n\\"))) def testProtocolSend(self): testConnection = TestConnection() self.gateway = JavaGateway(testConnection, False) e = self.gateway.getExample() self.assertEqual('c\nt\ngetExample\ne\n', testConnection.last_message) e.method1(1, True, 'Hello\nWorld', e, None, 1.5) self.assertEqual( 'c\no0\nmethod1\ni1\nbTrue\nsHello\\nWorld\nro0\nn\nd1.5\ne\n', testConnection.last_message) del(e) def testProtocolReceive(self): p = start_echo_server_process() time.sleep(1) try: testSocket = get_socket() testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('yro0\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('ysHello World\n'.encode('utf-8')) # No extra echange (method3) because it is already cached. testSocket.sendall('yi123\n'.encode('utf-8')) testSocket.sendall('yd1.25\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('yn\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('ybTrue\n'.encode('utf-8')) testSocket.sendall('yo\n'.encode('utf-8')) testSocket.sendall('yL123\n'.encode('utf-8')) testSocket.close() time.sleep(1) self.gateway = JavaGateway(auto_field=True) ex = self.gateway.getNewExample() self.assertEqual('Hello World', ex.method3(1, True)) self.assertEqual(123, ex.method3()) self.assertAlmostEqual(1.25, ex.method3()) self.assertTrue(ex.method2() is None) self.assertTrue(ex.method4()) self.assertEqual(long(123), ex.method8()) self.gateway.shutdown() except Exception as e: print('Error has occurred', e) print_exc() self.fail('Problem occurred') p.join()
class ProtocolTest(unittest.TestCase): def tearDown(self): # Safety check in case there was an exception... safe_shutdown(self) def testEscape(self): self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\"))) self.assertEqual("Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\"))) def testProtocolSend(self): testConnection = TestConnection() self.gateway = JavaGateway() # Replace gateway client by test connection self.gateway.set_gateway_client(testConnection) e = self.gateway.getExample() self.assertEqual("c\nt\ngetExample\ne\n", testConnection.last_message) e.method1(1, True, "Hello\nWorld", e, None, 1.5) self.assertEqual("c\no0\nmethod1\ni1\nbTrue\nsHello\\nWorld\nro0\nn\nd1.5\ne\n", testConnection.last_message) del (e) def testProtocolReceive(self): p = start_echo_server_process() try: testSocket = get_socket() testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!yro0\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!ysHello World\n".encode("utf-8")) # No extra echange (method3) because it is already cached. testSocket.sendall("!yi123\n".encode("utf-8")) testSocket.sendall("!yd1.25\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!yn\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!ybTrue\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!yL123\n".encode("utf-8")) testSocket.sendall("!ydinf\n".encode("utf-8")) testSocket.close() sleep() self.gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_field=True)) ex = self.gateway.getNewExample() self.assertEqual("Hello World", ex.method3(1, True)) self.assertEqual(123, ex.method3()) self.assertAlmostEqual(1.25, ex.method3()) self.assertTrue(ex.method2() is None) self.assertTrue(ex.method4()) self.assertEqual(long(123), ex.method8()) self.assertEqual(float("inf"), ex.method8()) self.gateway.shutdown() except Exception: print_exc() self.fail("Problem occurred") p.join()
class ProtocolTest(unittest.TestCase): def tearDown(self): # Safety check in case there was an exception... safe_shutdown(self) def testEscape(self): self.assertEqual( "Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\"))) self.assertEqual( "Hello\t\rWorld\n\\", unescape_new_line(escape_new_line("Hello\t\rWorld\n\\"))) def testProtocolSend(self): testConnection = TestConnection() self.gateway = JavaGateway() # Replace gateway client by test connection self.gateway.set_gateway_client(testConnection) e = self.gateway.getExample() self.assertEqual("c\nt\ngetExample\ne\n", testConnection.last_message) e.method1(1, True, "Hello\nWorld", e, None, 1.5) self.assertEqual( "c\no0\nmethod1\ni1\nbTrue\nsHello\\nWorld\nro0\nn\nd1.5\ne\n", testConnection.last_message) del (e) def testProtocolReceive(self): p = start_echo_server_process() try: testSocket = get_socket() testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!yro0\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!ysHello World\n".encode("utf-8")) # No extra echange (method3) because it is already cached. testSocket.sendall("!yi123\n".encode("utf-8")) testSocket.sendall("!yd1.25\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!yn\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!ybTrue\n".encode("utf-8")) testSocket.sendall("!yo\n".encode("utf-8")) testSocket.sendall("!yL123\n".encode("utf-8")) testSocket.sendall("!ydinf\n".encode("utf-8")) testSocket.close() sleep() self.gateway = JavaGateway(gateway_parameters=GatewayParameters( auto_field=True)) ex = self.gateway.getNewExample() self.assertEqual("Hello World", ex.method3(1, True)) self.assertEqual(123, ex.method3()) self.assertAlmostEqual(1.25, ex.method3()) self.assertTrue(ex.method2() is None) self.assertTrue(ex.method4()) self.assertEqual(long(123), ex.method8()) self.assertEqual(float("inf"), ex.method8()) self.gateway.shutdown() except Exception: print_exc() self.fail("Problem occurred") p.join()