##// END OF EJS Templates
Merge pull request #10269 from StevenMaude/correct-filelink-docstring...
Merge pull request #10269 from StevenMaude/correct-filelink-docstring Fix docstring of FileLink to match parameter name

File last commit:

r23129:81d5575c
r23330:d1a99b16 merge
Show More
globalipapp.py
136 lines | 4.5 KiB | text/x-python | PythonLexer
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423 """Global IPython app to support test running.
We must start our own ipython object and heavily muck with it so that all the
modifications IPython makes to system behavior don't send the doctest machinery
into a fit. This code should be considered a gross hack, but it gets the job
done.
"""
Min RK
fix some deprecations...
r22742 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Thomas Kluyver
Remove uses of compatibility builtin_mod and builtin_mod_name
r23129 import builtins as builtin_mod
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423 import sys
Min RK
fix some deprecations...
r22742 import warnings
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423
from . import tools
Thomas Kluyver
Disable the pager for the test suite....
r5263 from IPython.core import page
MinRK
Add StreamProxy soft link io.stdout/err to sys.stdout/err...
r3801 from IPython.utils import io
Thomas Kluyver
Fix various problems highlighted by the test suite.
r4759 from IPython.utils import py3compat
Fernando Perez
Fix all remaining imports that used `IPython.frontend`.
r11024 from IPython.terminal.interactiveshell import TerminalInteractiveShell
Fernando Perez
Fixed broken coloring on Windows....
r2974
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423
MinRK
Add StreamProxy soft link io.stdout/err to sys.stdout/err...
r3801 class StreamProxy(io.IOStream):
"""Proxy for sys.stdout/err. This will request the stream *at call time*
allowing for nose's Capture plugin's redirection of sys.stdout/err.
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
Add StreamProxy soft link io.stdout/err to sys.stdout/err...
r3801 Parameters
----------
name : str
The name of the stream. This will be requested anew at every call
"""
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
Add StreamProxy soft link io.stdout/err to sys.stdout/err...
r3801 def __init__(self, name):
Min RK
fix some deprecations...
r22742 warnings.warn("StreamProxy is deprecated and unused as of IPython 5", DeprecationWarning,
stacklevel=2,
)
MinRK
Add StreamProxy soft link io.stdout/err to sys.stdout/err...
r3801 self.name=name
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
Add StreamProxy soft link io.stdout/err to sys.stdout/err...
r3801 @property
def stream(self):
return getattr(sys, self.name)
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
Add StreamProxy soft link io.stdout/err to sys.stdout/err...
r3801 def flush(self):
self.stream.flush()
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423
def get_ipython():
# This will get replaced by the real thing once we start IPython below
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 return start_ipython()
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423
Brian Granger
More work addressing review comments for Fernando's branch....
r2499
Fernando Perez
Fixed broken coloring on Windows....
r2974 # A couple of methods to override those in the running IPython to interact
# better with doctest (doctest captures on raw stdout, so we need to direct
# various types of output there otherwise it will miss them).
def xsys(self, cmd):
"""Replace the default system call with a capturing one for doctest.
"""
# We use getoutput, but we need to strip it because pexpect captures
# the trailing newline differently from commands.getoutput
Thomas Kluyver
Expose & document depth parameter to ip.getoutput()
r7400 print(self.getoutput(cmd, split=False, depth=1).rstrip(), end='', file=sys.stdout)
Fernando Perez
Fixed broken coloring on Windows....
r2974 sys.stdout.flush()
def _showtraceback(self, etype, evalue, stb):
"""Print the traceback purely on stdout for doctest to capture it.
"""
print(self.InteractiveTB.stb2text(stb), file=sys.stdout)
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423 def start_ipython():
"""Start a global IPython shell, which we need for IPython-specific syntax.
"""
global get_ipython
# This function should only ever run once!
Brian Granger
More work addressing review comments for Fernando's branch....
r2499 if hasattr(start_ipython, 'already_called'):
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423 return
start_ipython.already_called = True
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423 # Store certain global objects that IPython modifies
_displayhook = sys.displayhook
_excepthook = sys.excepthook
_main = sys.modules.get('__main__')
Fernando Perez
Clean up and document better starting process of global IPython in tests.
r2444 # Create custom argv and namespaces for our IPython to be test-friendly
Brian Granger
More work addressing review comments for Fernando's branch....
r2499 config = tools.default_config()
Matthias Bussonnier
Use SIMPLE_PROMPT while testing....
r22573 config.TerminalInteractiveShell.simple_prompt = True
Brian Granger
More work addressing review comments for Fernando's branch....
r2499
Fernando Perez
Clean up and document better starting process of global IPython in tests.
r2444 # Create and initialize our test-friendly IPython instance.
Bernardo B. Marques
remove all trailling spaces
r4872 shell = TerminalInteractiveShell.instance(config=config,
Fernando Perez
Fixed broken coloring on Windows....
r2974 )
Fernando Perez
Clean up and document better starting process of global IPython in tests.
r2444
# A few more tweaks needed for playing nicely with doctests...
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
add test history db to shell.tempfiles for cleanup...
r4602 # remove history file
shell.tempfiles.append(config.HistoryManager.hist_file)
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Clean up and document better starting process of global IPython in tests.
r2444 # These traps are normally only active for interactive use, set them
# permanently since we'll be mocking interactive sessions.
Fernando Perez
Speedup builtin_trap enter/exit by reducing object creation....
r2957 shell.builtin_trap.activate()
Fernando Perez
Changed %hist to default to NOT printing numbers, added -p and -o options....
r2441
Fernando Perez
Clean up and document better starting process of global IPython in tests.
r2444 # Modify the IPython system call with one that uses getoutput, so that we
# can capture subcommands and print them to Python's stdout, otherwise the
# doctest machinery would miss them.
Thomas Kluyver
Fix various problems highlighted by the test suite.
r4759 shell.system = py3compat.MethodType(xsys, shell)
Thomas Kluyver
Use user_ns as global namespace if it is passed without user_module, and add test for pickling interactively defined objects....
r5456
Thomas Kluyver
Fix various problems highlighted by the test suite.
r4759 shell._showtraceback = py3compat.MethodType(_showtraceback, shell)
Fernando Perez
Clean up and document better starting process of global IPython in tests.
r2444
# IPython is ready, now clean up some global state...
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423 # Deactivate the various python system hooks added by ipython for
# interactive convenience so we don't confuse the doctest system
sys.modules['__main__'] = _main
sys.displayhook = _displayhook
sys.excepthook = _excepthook
# So that ipython magics and aliases can be doctested (they work by making
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 # a call into a global _ip object). Also make the top-level get_ipython
Fernando Perez
Clean up and document better starting process of global IPython in tests.
r2444 # now return this without recursively calling here again.
Brian Granger
More work addressing review comments for Fernando's branch....
r2499 _ip = shell
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423 get_ipython = _ip.get_ipython
Thomas Kluyver
Repair various failures in the test suite.
r4734 builtin_mod._ip = _ip
builtin_mod.get_ipython = get_ipython
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Disable the pager for the test suite....
r5263 # Override paging, so we don't require user interaction during the tests.
def nopage(strng, start=0, screen_lines=0, pager_cmd=None):
Matthias Bussonnier
Fix test mimebundle paging...
r22464 if isinstance(strng, dict):
strng = strng.get('text/plain', '')
Thomas Kluyver
Disable the pager for the test suite....
r5263 print(strng)
Thomas Kluyver
Replace pager_page() instead of page() for test suite...
r19436 page.orig_page = page.pager_page
page.pager_page = nopage
Fernando Perez
Add file I forgot! Thanks to J. Hunter for report.
r2423
Fernando Perez
Lots of work on exception handling, including tests for traceback printing....
r2440 return _ip