コード例 #1
0
    def test_all_regular_signals(self):
        listener = MockListener(self)

        server_started.connect(listener.started)

        hello_state = HelloState()
        client_server = ClientServer(JavaParameters(), PythonParameters(),
                                     hello_state)
        server_stopped.connect(listener.stopped,
                               sender=client_server.get_callback_server())
        server_connection_started.connect(
            listener.connection_started,
            sender=client_server.get_callback_server())
        server_connection_stopped.connect(
            listener.connection_stopped,
            sender=client_server.get_callback_server())
        pre_server_shutdown.connect(listener.pre_shutdown,
                                    sender=client_server.get_callback_server())
        post_server_shutdown.connect(
            listener.post_shutdown, sender=client_server.get_callback_server())
        with clientserver_example_app_process(True):
            client_server.shutdown()

        self.assertEqual(1, listener.received["started"])
        self.assertEqual(1, listener.received["stopped"])
        self.assertEqual(1, listener.received["pre_shutdown"])
        self.assertEqual(1, listener.received["post_shutdown"])
        self.assertEqual(1, listener.received["connection_started"])
        self.assertEqual(1, listener.received["connection_stopped"])
コード例 #2
0
    def testJavaClientPythonServer(self):
        hello_state = HelloState()
        client_server = ClientServer(JavaParameters(), PythonParameters(),
                                     hello_state)

        with clientserver_example_app_process(True):
            client_server.shutdown()

        # Check that Java correctly called Python
        self.assertEqual(2, len(hello_state.calls))
        self.assertEqual((None, None), hello_state.calls[0])
        self.assertEqual((2, "Hello World"), hello_state.calls[1])
コード例 #3
0
    def test_python_entry_point(self):
        from py4j.tests.py4j_callback_recursive_example import (HelloState)
        hello_state = HelloState()
        gateway = JavaGateway(
            callback_server_parameters=CallbackServerParameters(),
            python_server_entry_point=hello_state)

        with gateway_example_app_process("pythonentrypoint"):
            gateway.shutdown()

        # Check that Java correctly called Python
        self.assertEqual(2, len(hello_state.calls))
        self.assertEqual((None, None), hello_state.calls[0])
        self.assertEqual((2, "Hello World"), hello_state.calls[1])
コード例 #4
0
ファイル: java_callback_test.py プロジェクト: Ditto0/Sparks
    def _run_test(self, auth_token=None):
        from py4j.tests.py4j_callback_recursive_example import (HelloState)
        hello_state = HelloState()
        cb_params = CallbackServerParameters(auth_token=auth_token)
        gateway = JavaGateway(callback_server_parameters=cb_params,
                              python_server_entry_point=hello_state)

        args = []
        if auth_token:
            args = [auth_token]
        with gateway_example_app_process("pythonentrypoint", args):
            gateway.shutdown()

        # Check that Java correctly called Python
        self.assertEqual(2, len(hello_state.calls))
        self.assertEqual((None, None), hello_state.calls[0])
        self.assertEqual((2, "Hello World"), hello_state.calls[1])