<s> import unittest <EOL> try : <EOL> import IPython <EOL> except ImportError : <EOL> from nose . plugins . skip import SkipTest <EOL> raise SkipTest ( '<STR_LIT>' ) <EOL> from IPython . kernel . zmq . kernelapp import IPKernelApp <EOL> from envisage . api import Application , Plugin <EOL> from envisage . core_plugin import CorePlugin <EOL> from envisage . plugins . ipython_kernel . internal_ipkernel import InternalIPKernel <EOL> from envisage . plugins . ipython_kernel . ipython_kernel_plugin import ( <EOL> IPYTHON_KERNEL_PROTOCOL , IPYTHON_NAMESPACE , IPythonKernelPlugin ) <EOL> from traits . api import List <EOL> class TestIPythonKernelPlugin ( unittest . TestCase ) : <EOL> def tearDown ( self ) : <EOL> IPKernelApp . clear_instance ( ) <EOL> def test_kernel_service ( self ) : <EOL> plugins = [ CorePlugin ( ) , IPythonKernelPlugin ( ) ] <EOL> app = Application ( plugins = plugins , id = '<STR_LIT:test>' ) <EOL> app . start ( ) <EOL> kernel = app . get_service ( IPYTHON_KERNEL_PROTOCOL ) <EOL> self . assertIsNotNone ( kernel ) <EOL> self . assertIsInstance ( kernel , InternalIPKernel ) <EOL> kernel . init_ipkernel ( gui_backend = None ) <EOL> app . stop ( ) <EOL> self . assertIsNone ( kernel . ipkernel ) <EOL> def test_kernel_namespace_extension_point ( self ) : <EOL> class NamespacePlugin ( Plugin ) : <EOL> kernel_namespace = List ( contributes_to = IPYTHON_NAMESPACE ) <EOL> def _kernel_namespace_default ( self ) : <EOL> return [ ( '<STR_LIT:y>' , '<STR_LIT>' ) ] <EOL> plugins = [ CorePlugin ( ) , IPythonKernelPlugin ( ) , NamespacePlugin ( ) ] <EOL> app = Application ( plugins = plugins , id = '<STR_LIT:test>' ) <EOL> app . start ( ) <EOL> try : <EOL> kernel = app . get_service ( IPYTHON_KERNEL_PROTOCOL ) <EOL> kernel . init_ipkernel ( gui_backend = None ) <EOL> self . assertIn ( '<STR_LIT:y>' , kernel . namespace ) <EOL> self . assertEqual ( kernel . namespace [ '<STR_LIT:y>' ] , '<STR_LIT>' ) <EOL> finally : <EOL> app . stop ( ) </s>
