Beispiel #1
0
    def test_service_used(self):
        # This is a complement to the test_service_not_used test. It's mostly
        # here as a double check on the somewhat messy test machinery used in
        # test_service_not_used: if the assumptions (e.g., on the location that
        # InternalIPKernel is imported from) in test_service_not_used break,
        # then this test will likely break too.

        from envisage.plugins.ipython_kernel import internal_ipkernel

        kernel_instances = []

        class TrackingInternalIPKernel(internal_ipkernel.InternalIPKernel):
            def __init__(self, *args, **kwargs):
                super().__init__(*args, **kwargs)
                kernel_instances.append(self)

        patcher = mock.patch.object(
            internal_ipkernel, "InternalIPKernel", TrackingInternalIPKernel,
        )

        with patcher:
            kernel_plugin = IPythonKernelPlugin(init_ipkernel=True)
            with self.running_app(plugins=[kernel_plugin]) as app:
                app.get_service(IPYTHON_KERNEL_PROTOCOL)

        self.assertEqual(len(kernel_instances), 1)
Beispiel #2
0
    def test_no_init(self):
        # Testing deprecated behaviour where the kernel is not initialized.
        plugins = [IPythonKernelPlugin()]

        with self.running_app(plugins=plugins) as app:
            with warnings.catch_warnings(record=True) as warn_msgs:
                warnings.simplefilter("always", category=DeprecationWarning)
                app.get_service(IPYTHON_KERNEL_PROTOCOL)

        matching_messages = [
            msg for msg in warn_msgs
            if isinstance(msg.message, DeprecationWarning)
            if "kernel will be initialized" in str(msg.message)
        ]
        self.assertEqual(len(matching_messages), 1)
Beispiel #3
0
    def test_kernel_namespace_extension_point(self):
        class NamespacePlugin(Plugin):
            kernel_namespace = List(contributes_to=IPYTHON_NAMESPACE)

            def _kernel_namespace_default(self):
                return [("y", "hi")]

        plugins = [
            IPythonKernelPlugin(init_ipkernel=True),
            NamespacePlugin(),
        ]

        with self.running_app(plugins=plugins) as app:
            kernel = app.get_service(IPYTHON_KERNEL_PROTOCOL)
            self.assertIn("y", kernel.namespace)
            self.assertEqual(kernel.namespace["y"], "hi")
Beispiel #4
0
    def running_app(self, plugins=None):
        """
        Returns a context manager that provides a running application.

        Parameters
        ----------
        plugins : list of Plugin, optional
            Plugins to use in the application, other than the CorePlugin
            (which is always included). If not given, an IPythonKernelPlugin
            is instantiated and used.
        """
        if plugins is None:
            plugins = [IPythonKernelPlugin(init_ipkernel=True)]

        app = Application(plugins=[CorePlugin()] + plugins, id="test")
        app.start()
        try:
            yield app
        finally:
            app.stop()
Beispiel #5
0
    def test_service_not_used(self):
        # If the service isn't used, no kernel should be created.
        from envisage.plugins.ipython_kernel import internal_ipkernel

        kernel_instances = []

        class TrackingInternalIPKernel(internal_ipkernel.InternalIPKernel):
            def __init__(self, *args, **kwargs):
                super().__init__(*args, **kwargs)
                kernel_instances.append(self)

        patcher = mock.patch.object(
            internal_ipkernel, "InternalIPKernel", TrackingInternalIPKernel,
        )

        with patcher:
            kernel_plugin = IPythonKernelPlugin(init_ipkernel=True)
            with self.running_app(plugins=[kernel_plugin]):
                pass

        self.assertEqual(kernel_instances, [])
Beispiel #6
0
            # Create windows from the default or saved application layout.
            self._create_windows()

            kernel = self.get_service(IPYTHON_KERNEL_PROTOCOL)
            kernel.init_ipkernel('qt4')

            app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
                        app, QtCore.SLOT("quit()"))
            app.aboutToQuit.connect(kernel.cleanup_consoles)

            gui.set_trait_later(self, 'application_initialized', self)
            kernel.ipkernel.start()

        return started

    def _application_initialized_fired(self):
        logger.info('APPLICATION INITIALIZED')

if __name__ == '__main__':
    import logging
    logging.basicConfig(level=logging.DEBUG)

    app = ExampleApplication(
        plugins=[
            CorePlugin(), ExamplePlugin(), IPythonKernelPlugin(),
            IPythonKernelUIPlugin(), TasksPlugin(),
        ]
    )
    app.run()
            self._create_windows()

            kernel = self.get_service(IPYTHON_KERNEL_PROTOCOL)
            kernel.init_ipkernel('qt4')

            app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app,
                        QtCore.SLOT("quit()"))
            app.aboutToQuit.connect(kernel.cleanup_consoles)

            gui.set_trait_later(self, 'application_initialized', self)
            kernel.ipkernel.start()

        return started

    def _application_initialized_fired(self):
        logger.info('APPLICATION INITIALIZED')


if __name__ == '__main__':
    import logging
    logging.basicConfig(level=logging.DEBUG)

    app = ExampleApplication(plugins=[
        CorePlugin(),
        ExamplePlugin(),
        IPythonKernelPlugin(),
        IPythonKernelUIPlugin(),
        TasksPlugin(),
    ])
    app.run()