##// END OF EJS Templates
Robustness fixes in test suite machinery....
Robustness fixes in test suite machinery. Added a module-level INSTALLED flag, which can be set to false if the test suite is being run in-place (without ipython having been installed at all). This is because how we call and import things must be done differently depending on whether the code is installed or is being run in-place. The only ones that can know this reliably are the entry-point scripts, so those are responsible for setting this flag. Also made the code that validates ipython in subprocesses report errors better, by checking stderr for errors before validating stdout output, as anything on stderr will be likely informative of the real problem.

File last commit:

r2289:e432bee0 merge
r2494:c8938204
Show More
display_trap.py
77 lines | 2.3 KiB | text/x-python | PythonLexer
Brian Granger
sys.displayhook is now managed dynamically by display_trap.
r2231 #!/usr/bin/env python
# encoding: utf-8
"""
A context manager for handling sys.displayhook.
Authors:
* Robert Kern
* Brian Granger
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2009 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
#-----------------------------------------------------------------------------
import sys
from IPython.core.component import Component
Brian Granger
More work on refactoring things into components....
r2244 from IPython.utils.autoattr import auto_attr
Brian Granger
sys.displayhook is now managed dynamically by display_trap.
r2231 #-----------------------------------------------------------------------------
# Classes and functions
#-----------------------------------------------------------------------------
class DisplayTrap(Component):
"""Object to manage sys.displayhook.
This came from IPython.core.kernel.display_hook, but is simplified
(no callbacks or formatters) until more of the core is refactored.
"""
def __init__(self, parent, hook):
super(DisplayTrap, self).__init__(parent, None, None)
self.hook = hook
self.old_hook = None
Brian Granger
Massive refactoring of of the core....
r2245 # We define this to track if a single BuiltinTrap is nested.
# Only turn off the trap when the outermost call to __exit__ is made.
self._nested_level = 0
Brian Granger
sys.displayhook is now managed dynamically by display_trap.
r2231
Brian Granger
Work on refactoring ipcontroller to new config system.
r2287 # @auto_attr
# def shell(self):
# return Component.get_instances(
# root=self.root,
# klass='IPython.core.iplib.InteractiveShell')[0]
Brian Granger
More work on refactoring things into components....
r2244
Brian Granger
sys.displayhook is now managed dynamically by display_trap.
r2231 def __enter__(self):
Brian Granger
Massive refactoring of of the core....
r2245 if self._nested_level == 0:
self.set()
self._nested_level += 1
Brian Granger
sys.displayhook is now managed dynamically by display_trap.
r2231 return self
def __exit__(self, type, value, traceback):
Brian Granger
Massive refactoring of of the core....
r2245 if self._nested_level == 1:
self.unset()
self._nested_level -= 1
Brian Granger
The pretty.py extension has been ported to the new extension API....
r2281 # Returning False will cause exceptions to propagate
return False
Brian Granger
sys.displayhook is now managed dynamically by display_trap.
r2231
def set(self):
"""Set the hook."""
if sys.displayhook is not self.hook:
self.old_hook = sys.displayhook
sys.displayhook = self.hook
def unset(self):
"""Unset the hook."""
sys.displayhook = self.old_hook