コード例 #1
0
ファイル: test_kernelmanager.py プロジェクト: 3kwa/ipython
 def test_execute(self):
     """ Does executing code in an in-process kernel work?
     """
     km = BlockingInProcessKernelManager()
     km.start_kernel()
     km.shell_channel.execute('foo = 1')
     self.assertEquals(km.kernel.shell.user_ns['foo'], 1)
コード例 #2
0
ファイル: test_kernel.py プロジェクト: techtonik/ipython
 def test_pylab(self):
     """ Does pylab work in the in-process kernel?
     """
     km = BlockingInProcessKernelManager()
     km.start_kernel()
     km.shell_channel.execute('%pylab')
     msg = get_stream_message(km)
     self.assert_('Welcome to pylab' in msg['content']['data'])
コード例 #3
0
ファイル: test_kernelmanager.py プロジェクト: 3kwa/ipython
 def test_object_info(self):
     """ Does requesting object information from an in-process kernel work?
     """
     km = BlockingInProcessKernelManager()
     km.start_kernel()
     km.kernel.shell.user_ns['foo'] = 1
     km.shell_channel.object_info('foo')
     msg = km.shell_channel.get_msg()
     self.assertEquals(msg['header']['msg_type'], 'object_info_reply')
     self.assertEquals(msg['content']['name'], 'foo')
     self.assertEquals(msg['content']['type_name'], 'int')
コード例 #4
0
ファイル: test_kernelmanager.py プロジェクト: 3kwa/ipython
 def test_complete(self):
     """ Does requesting completion from an in-process kernel work?
     """
     km = BlockingInProcessKernelManager()
     km.start_kernel()
     km.kernel.shell.push({'my_bar': 0, 'my_baz': 1})
     km.shell_channel.complete('my_ba', 'my_ba', 5)
     msg = km.shell_channel.get_msg()
     self.assertEquals(msg['header']['msg_type'], 'complete_reply')
     self.assertEquals(sorted(msg['content']['matches']),
                       ['my_bar', 'my_baz'])
コード例 #5
0
ファイル: test_kernelmanager.py プロジェクト: 3kwa/ipython
 def test_history(self):
     """ Does requesting history from an in-process kernel work?
     """
     km = BlockingInProcessKernelManager()
     km.start_kernel()
     km.shell_channel.execute('%who')
     km.shell_channel.history(hist_access_type='tail', n=1)
     msg = km.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
ファイル: test_kernel.py プロジェクト: techtonik/ipython
    def test_raw_input(self):
        """ Does the in-process kernel handle raw_input correctly?
        """
        km = BlockingInProcessKernelManager()
        km.start_kernel()

        io = StringIO('foobar\n')
        sys_stdin = sys.stdin
        sys.stdin = io
        try:
            if py3compat.PY3:
                km.shell_channel.execute('x = input()')
            else:
                km.shell_channel.execute('x = raw_input()')
        finally:
            sys.stdin = sys_stdin
        self.assertEqual(km.kernel.shell.user_ns.get('x'), 'foobar')
コード例 #7
0
ファイル: test_kernel.py プロジェクト: techtonik/ipython
    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')

        km = BlockingInProcessKernelManager(kernel=kernel)
        kernel.frontends.append(km)
        km.shell_channel.execute('print("bar")')
        msg = get_stream_message(km)
        self.assertEqual(msg['content']['data'], 'bar\n')
コード例 #8
0
ファイル: test_kernelmanager.py プロジェクト: 3kwa/ipython
    def test_inteface(self):
        """ Does the in-process kernel manager implement the basic KM interface?
        """
        km = BlockingInProcessKernelManager()
        self.assert_(not km.channels_running)
        self.assert_(not km.has_kernel)

        km.start_channels()
        self.assert_(km.channels_running)

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

        old_kernel = km.kernel
        km.restart_kernel()
        self.assert_(km.kernel is not None)
        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)

        km.stop_channels()
        self.assert_(not km.channels_running)