##// END OF EJS Templates
normalize unicode notebook filenames...
normalize unicode notebook filenames used in comparison check for notebook name change. Unless the filenames are normalized, unchanged names may result in false positives for a name change (e.g. OS X uses NFD on the filesystem, so u'\xfc' roundtripped to the filesystem will be u'u\u0308'), which can result in the first save of a notebook after open performing the following actions: 1. save the recently opened notebook 2. `old_name != new_name`, so name change detected 3. delete old_name (which is actually new_name), which ultimately deletes the just-saved notebook In master, this has a symptom of the first checkpoint failing because the first save actually deleted the file, and you can't checkpoint a notebook that doesn't exist. closes #3360

File last commit:

r10298:49d3c39a
r10777:9585bda6
Show More
test_kernel.py
91 lines | 3.1 KiB | text/x-python | PythonLexer
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 #-------------------------------------------------------------------------------
# Copyright (C) 2012 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-------------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from __future__ import print_function
# Standard library imports
epatters
BUG: raw_input logic incorrect for in-process terminal frontend.
r8482 from StringIO import StringIO
import sys
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 import unittest
# Local imports
MinRK
update inprocess kernel to new layout...
r10298 from IPython.kernel.inprocess.blocking import BlockingInProcessKernelClient
from IPython.kernel.inprocess.manager import InProcessKernelManager
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 from IPython.kernel.inprocess.ipkernel import InProcessKernel
epatters
TST: Skip pylab test for in-process kernel when matplotlib is missing.
r8493 from IPython.testing.decorators import skipif_not_matplotlib
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 from IPython.utils.io import capture_output
Pietro Berkes
BUG: In inprocess tests, use input/raw_input depending on Python version.
r8941 from IPython.utils import py3compat
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475
#-----------------------------------------------------------------------------
# Test case
#-----------------------------------------------------------------------------
class InProcessKernelTestCase(unittest.TestCase):
MinRK
update inprocess kernel to new layout...
r10298 def setUp(self):
self.km = InProcessKernelManager()
self.km.start_kernel()
self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
self.kc.start_channels()
epatters
TST: Skip pylab test for in-process kernel when matplotlib is missing.
r8493 @skipif_not_matplotlib
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 def test_pylab(self):
""" Does pylab work in the in-process kernel?
"""
MinRK
update inprocess kernel to new layout...
r10298 kc = self.kc
kc.execute('%pylab')
msg = get_stream_message(kc)
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 self.assert_('Welcome to pylab' in msg['content']['data'])
epatters
BUG: raw_input logic incorrect for in-process terminal frontend.
r8482 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:
Pietro Berkes
BUG: In inprocess tests, use input/raw_input depending on Python version.
r8941 if py3compat.PY3:
MinRK
update inprocess kernel to new layout...
r10298 self.kc.execute('x = input()')
Pietro Berkes
BUG: In inprocess tests, use input/raw_input depending on Python version.
r8941 else:
MinRK
update inprocess kernel to new layout...
r10298 self.kc.execute('x = raw_input()')
epatters
BUG: raw_input logic incorrect for in-process terminal frontend.
r8482 finally:
sys.stdin = sys_stdin
MinRK
update inprocess kernel to new layout...
r10298 self.assertEqual(self.km.kernel.shell.user_ns.get('x'), 'foobar')
epatters
BUG: raw_input logic incorrect for in-process terminal frontend.
r8482
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 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')
MinRK
update inprocess kernel to new layout...
r10298 kc = BlockingInProcessKernelClient(kernel=kernel)
kernel.frontends.append(kc)
kc.shell_channel.execute('print("bar")')
msg = get_stream_message(kc)
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 self.assertEqual(msg['content']['data'], 'bar\n')
#-----------------------------------------------------------------------------
# Utility functions
#-----------------------------------------------------------------------------
MinRK
update inprocess kernel to new layout...
r10298 def get_stream_message(kernel_client, timeout=5):
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 """ Gets a single stream message synchronously from the sub channel.
"""
while True:
MinRK
update inprocess kernel to new layout...
r10298 msg = kernel_client.get_iopub_msg(timeout=timeout)
epatters
TST: Add some unit tests for in-process kernel and kernel manager.
r8475 if msg['header']['msg_type'] == 'stream':
return msg
if __name__ == '__main__':
unittest.main()