Пример #1
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)
Пример #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)
Пример #3
0
    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, "foo\n")

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.execute('print("bar")')
        out, err = assemble_output(kc.iopub_channel)
        self.assertEqual(out, "bar\n")
Пример #4
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')
Пример #5
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')
Пример #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")
Пример #7
0
    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, 'foo\n')

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.execute('print("bar")')
        msg = get_stream_message(kc)
        self.assertEqual(msg['content']['text'], 'bar\n')
Пример #8
0
    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, 'foo\n')

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.execute('print("bar")')
        out, err = assemble_output(kc.iopub_channel)
        self.assertEqual(out, 'bar\n')
Пример #9
0
class InProcessKernelTestCase(unittest.TestCase):

    def setUp(self):
        self.km = InProcessKernelManager()
        self.km.start_kernel()
        self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
        self.kc.start_channels()

    @skipif_not_matplotlib
    def test_pylab(self):
        """ Does pylab work in the in-process kernel?
        """
        kc = self.kc
        kc.execute('%pylab')
        msg = get_stream_message(kc)
        self.assert_('Welcome to pylab' in msg['content']['data'])

    def test_raw_input(self):
        """ Does the in-process kernel handle raw_input correctly?
        """
        io = StringIO('foobar\n')
        sys_stdin = sys.stdin
        sys.stdin = io
        try:
            if py3compat.PY3:
                self.kc.execute('x = input()')
            else:
                self.kc.execute('x = raw_input()')
        finally:
            sys.stdin = sys_stdin
        self.assertEqual(self.km.kernel.shell.user_ns.get('x'), 'foobar')

    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, 'foo\n')

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.shell_channel.execute('print("bar")')
        msg = get_stream_message(kc)
        self.assertEqual(msg['content']['data'], 'bar\n')
class InProcessKernelTestCase(unittest.TestCase):

    def setUp(self):
        self.km = InProcessKernelManager()
        self.km.start_kernel()
        self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
        self.kc.start_channels()

    @skipif_not_matplotlib
    def test_pylab(self):
        """ Does pylab work in the in-process kernel?
        """
        kc = self.kc
        kc.execute('%pylab')
        msg = get_stream_message(kc)
        self.assert_('matplotlib' in msg['content']['data'])

    def test_raw_input(self):
        """ Does the in-process kernel handle raw_input correctly?
        """
        io = StringIO('foobar\n')
        sys_stdin = sys.stdin
        sys.stdin = io
        try:
            if py3compat.PY3:
                self.kc.execute('x = input()')
            else:
                self.kc.execute('x = raw_input()')
        finally:
            sys.stdin = sys_stdin
        self.assertEqual(self.km.kernel.shell.user_ns.get('x'), 'foobar')

    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, 'foo\n')

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.shell_channel.execute('print("bar")')
        msg = get_stream_message(kc)
        self.assertEqual(msg['content']['data'], 'bar\n')
Пример #11
0
class InProcessKernelTestCase(unittest.TestCase):
    def setUp(self):
        self.km = InProcessKernelManager()
        self.km.start_kernel()
        self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
        self.kc.start_channels()
        self.kc.wait_for_ready()

    @skipif_not_matplotlib
    def test_pylab(self):
        """Does %pylab work in the in-process kernel?"""
        kc = self.kc
        kc.execute("%pylab")
        out, err = assemble_output(kc.iopub_channel)
        self.assertIn("matplotlib", out)

    def test_raw_input(self):
        """ Does the in-process kernel handle raw_input correctly?
        """
        io = StringIO("foobar\n")
        sys_stdin = sys.stdin
        sys.stdin = io
        try:
            if py3compat.PY3:
                self.kc.execute("x = input()")
            else:
                self.kc.execute("x = raw_input()")
        finally:
            sys.stdin = sys_stdin
        self.assertEqual(self.km.kernel.shell.user_ns.get("x"), "foobar")

    def test_stdout(self):
        """ Does the in-process kernel correctly capture IO?
        """
        kernel = InProcessKernel()

        with capture_output() as io:
            kernel.shell.run_cell('print("foo")')
        self.assertEqual(io.stdout, "foo\n")

        kc = BlockingInProcessKernelClient(kernel=kernel)
        kernel.frontends.append(kc)
        kc.execute('print("bar")')
        out, err = assemble_output(kc.iopub_channel)
        self.assertEqual(out, "bar\n")