Beispiel #1
0
 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'])
Beispiel #2
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')

        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')
Beispiel #3
0
    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')