Ejemplo n.º 1
0
    def test_interface(self):
        """ Does the in-process kernel manager implement the basic KM interface?
        """
        km = InProcessKernelManager()
        self.assert_(not km.has_kernel)

        km.start_kernel()
        self.assert_(km.has_kernel)
        self.assert_(km.kernel is not None)

        kc = BlockingInProcessKernelClient(kernel=km.kernel)
        self.assert_(not kc.channels_running)

        kc.start_channels()
        self.assert_(kc.channels_running)

        old_kernel = km.kernel
        km.restart_kernel()
        self.assertIsNotNone(km.kernel)
        self.assertNotEquals(km.kernel, old_kernel)

        km.shutdown_kernel()
        self.assert_(not km.has_kernel)

        self.assertRaises(NotImplementedError, km.interrupt_kernel)
        self.assertRaises(NotImplementedError, km.signal_kernel, 9)

        kc.stop_channels()
        self.assert_(not kc.channels_running)
Ejemplo n.º 2
0
 def test_execute(self):
     """ Does executing code in an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     kc.execute('foo = 1')
     self.assertEquals(km.kernel.shell.user_ns['foo'], 1)
Ejemplo n.º 3
0
 def test_object_info(self):
     """ Does requesting object information from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     km.kernel.shell.user_ns['foo'] = 1
     kc.object_info('foo')
     msg = kc.get_shell_msg()
     self.assertEquals(msg['header']['msg_type'], 'object_info_reply')
     self.assertEquals(msg['content']['name'], 'foo')
     self.assertEquals(msg['content']['type_name'], 'int')
Ejemplo n.º 4
0
 def test_complete(self):
     """ Does requesting completion from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     km.kernel.shell.push({'my_bar': 0, 'my_baz': 1})
     kc.complete('my_ba', 'my_ba', 5)
     msg = kc.get_shell_msg()
     self.assertEqual(msg['header']['msg_type'], 'complete_reply')
     self.assertEqual(sorted(msg['content']['matches']),
                      ['my_bar', 'my_baz'])
Ejemplo n.º 5
0
def get_kernel_pointer(buffer):
    lisp.message("getting kernel for " + buffer)
    if buffer not in kernels:
        lisp.message("creating new " + buffer)
        km = InProcessKernelManager()
        km.start_kernel()
        kc = BlockingInProcessKernelClient(kernel=km.kernel)
        kc.start_channels()
        kernel = InProcessKernel()
        kernels[buffer] = (kc, kernel, kernel.shell.get_ipython())
        # run this so that plt, np pointers are ready
        kc.shell_channel.execute('%pylab inline')
    return kernels[buffer]
Ejemplo n.º 6
0
 def test_history(self):
     """ Does requesting history from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     kc.execute('%who')
     kc.history(hist_access_type='tail', n=1)
     msg = kc.shell_channel.get_msgs()[-1]
     self.assertEquals(msg['header']['msg_type'], 'history_reply')
     history = msg['content']['history']
     self.assertEquals(len(history), 1)
     self.assertEquals(history[0][2], '%who')
Ejemplo n.º 7
0
 def test_inspect(self):
     """ Does requesting object information from an in-process kernel work?
     """
     km = InProcessKernelManager()
     km.start_kernel()
     kc = BlockingInProcessKernelClient(kernel=km.kernel)
     kc.start_channels()
     km.kernel.shell.user_ns['foo'] = 1
     kc.inspect('foo')
     msg = kc.get_shell_msg()
     self.assertEqual(msg['header']['msg_type'], 'inspect_reply')
     content = msg['content']
     assert content['found']
     text = content['data']['text/plain']
     self.assertIn('int', text)
Ejemplo n.º 8
0
 def setUp(self):
     self.km = InProcessKernelManager()
     self.km.start_kernel()
     self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
     self.kc.start_channels()
Ejemplo n.º 9
0
from Pymacs import lisp
import re, sys, time, os

interactions = {}
kernels = {}

from IPython.testing.globalipapp import get_ipython
from IPython.utils.io import capture_output

from IPython.kernel.inprocess.manager import InProcessKernelManager

km = InProcessKernelManager()

ip = get_ipython()


def run_cell(cmd):
    with capture_output() as io:
        res = ip.run_cell(cmd)
    res_out = io.stdout
    return res_out


ip.run_cell('import numpy as np')
ip.run_cell('import matplotlib.pylab as plt')
ip.run_cell('%load_ext autoreload')
ip.run_cell('%autoreload 2')


# make digits into length two - i.e. 1 into 01
def two_digit(i):
Ejemplo n.º 10
0
 def setUp(self):
     self.km = InProcessKernelManager()
     self.km.start_kernel()
     self.kc = self.km.client()
     self.kc.start_channels()
     self.kc.wait_for_ready()