def debug(self, err): import IPython ec, ev, tb = err stdout = sys.stdout sys.stdout = sys.__stdout__ sys.stderr.write('\n- TRACEBACK --------------------------------------------------------------------\n') traceback.print_exception(*err) sys.stderr.write('--------------------------------------------------------------------------------\n') try: # The IPython API changed a bit so we should # support the new version if hasattr(IPython, 'InteractiveShell'): shell = IPython.InteractiveShell() ip = IPython.core.ipapi.get() p = IPython.core.debugger.Pdb(ip.colors) # and keep support for older versions else: shell = IPython.Shell.IPShell(argv=['']) ip = IPython.ipapi.get() p = IPython.Debugger.Pdb(ip.options.colors) p.reset() # inspect.trace() returns a list of frame information from this # frame to the one that raised the exception being treated frame, filename, line, func_name, ctx, idx = inspect.trace()[-1] p.interaction(frame, tb) finally: sys.stdout = stdout
def post_mortem(tb): import IPython stdout = sys.stdout try: sys.stdout = sys.__stdout__ if hasattr(IPython, 'InteractiveShell'): if hasattr(IPython.InteractiveShell, 'instance'): shell = IPython.InteractiveShell.instance() p = IPython.core.debugger.Pdb(shell.colors) else: shell = IPython.InteractiveShell() ip = IPython.core.ipapi.get() p = IPython.core.debugger.Pdb(ip.colors) # and keep support for older versions else: shell = IPython.Shell.IPShell(argv=['']) ip = IPython.ipapi.get() p = IPython.Debugger.Pdb(ip.options.colors) p.reset() # inspect.getinnerframes() returns a list of frames information # from this frame to the one that raised the exception being # treated frame, filename, line, func_name, ctx, idx = inspect.getinnerframes( tb)[-1] p.interaction(frame, tb) finally: sys.stdout = stdout
def test_connect(self): if IPython is None: return rest_url = u'http://localhost:12345' execution_url = u'http://baz.qux:999' language = 'Elven' timeout = 999 ext = extension.MyriaExtension(shell=IPython.InteractiveShell()) connection = ext.connect(rest_url) self.assertEqual(connection._url_start, rest_url) line = u'{} {}'.format(rest_url, execution_url) connection = ext.connect(line) self.assertEqual(connection._url_start, rest_url) self.assertEqual(connection.execution_url, execution_url) line = u'{} {} -l Elven -t 999'.format(rest_url, execution_url) connection = ext.connect(line) self.assertEqual(connection._url_start, rest_url) self.assertEqual(connection.execution_url, execution_url) self.assertEqual(ext.language, language) self.assertEqual(ext.timeout, timeout)
def get_ipython(): import IPython shell = IPython.get_ipython() if shell is None: shell = IPython.InteractiveShell() IPython.get_ipython = shell.get_ipython return shell
def setUp(self): super(IPTestCase, self).setUp() try: import IPython from IPython.display import HTML, SVG self.ip = IPython.InteractiveShell() if self.ip is None: raise TypeError() except Exception: raise SkipTest("IPython could not be started") self.addTypeEqualityFunc(HTML, self.skip_comparison) self.addTypeEqualityFunc(SVG, self.skip_comparison)
def post_mortem(tb): import IPython try: stdout = sys.stdout frame = sys._getframe().f_back # The IPython API changed a bit so we should # support the new version stdout = sys.stdout sys.stdout = sys.__stdout__ shell = IPython.InteractiveShell() ip = IPython.core.ipapi.get() p = IPython.core.debugger.Pdb(ip.colors) p.reset() # inspect.trace() returns a list of frame information from this # frame to the one that raised the exception being treated ### frame, filename, line, func_name, ctx, idx = inspect.trace()[-1] p.interaction(frame, tb) finally: sys.stdout = stdout
def _start_debugger(self, tb): import Lifetime if Lifetime._shutdown_phase: return try: # try ipython if available import IPython try: IPython.InteractiveShell() p = IPython.core.debugger.Pdb(color_scheme='Linux') except AttributeError: # for ipython-0.10 or before IPython.Shell.IPShell(argv=[]) p = IPython.Debugger.Pdb(color_scheme=__IPYTHON__.rc.colors) p.reset() while tb.tb_next is not None: tb = tb.tb_next p.interaction(tb.tb_frame, tb) except ImportError: pdb.post_mortem(tb)
def setUp(self): super(DataTableTest, self).setUp() self.ip_patcher = mock.patch.object(IPython, 'get_ipython', autospec=True) get_ipython = self.ip_patcher.start() get_ipython.return_value = IPython.InteractiveShell()
def setup_class(cls): cls.ip = IPython.InteractiveShell() cls.ip.run_cell('import random') cls.ip.run_cell('import numpy as np') pymat.load_ipython_extension(cls.ip)