ipy_profile_doctest.py
46 lines
| 1.5 KiB
| text/x-python
|
PythonLexer
fperez
|
r750 | """Config file for 'doctest' profile. | ||
This profile modifies the prompts to be the standard Python ones, so that you | ||||
can generate easily doctests from an IPython session. | ||||
But more importantly, it enables pasting of code with '>>>' prompts and | ||||
arbitrary initial whitespace, as is typical of doctests in reST files and | ||||
docstrings. This allows you to easily re-run existing doctests and iteratively | ||||
work on them as part of your development workflow. | ||||
The exception mode is also set to 'plain' so the generated exceptions are as | ||||
similar as possible to the default Python ones, for inclusion in doctests.""" | ||||
# get various stuff that are there for historical / familiarity reasons | ||||
import ipy_legacy | ||||
Brian Granger
|
r2027 | from IPython.core import ipapi | ||
fperez
|
r750 | |||
Brian Granger
|
r2064 | from IPython.extensions import InterpreterPasteInput | ||
fperez
|
r750 | |||
def main(): | ||||
ip = ipapi.get() | ||||
o = ip.options | ||||
# Set the prompts similar to the defaults | ||||
o.prompt_in1 = '>>> ' | ||||
o.prompt_in2 = '... ' | ||||
o.prompt_out = '' | ||||
fperez
|
r766 | # Add a blank line before each new set of inputs. This is needed by | ||
# doctest to distinguish each test from the next. | ||||
o.separate_in = '\n' | ||||
fperez
|
r762 | o.separate_out = '' | ||
fperez
|
r766 | o.separate_out2 = '' | ||
fperez
|
r750 | |||
# Disable pprint, so that outputs are printed as similarly to standard | ||||
# python as possible | ||||
fperez
|
r762 | o.pprint = False | ||
fperez
|
r750 | |||
# Use plain exceptions, to also resemble normal pyhton. | ||||
o.xmode = 'plain' | ||||
fperez
|
r763 | # Store the activity flag in the metadata bag from the running shell | ||
Brian Granger
|
r2205 | ip.meta.doctest_mode = True | ||
fperez
|
r763 | |||
fperez
|
r750 | main() | ||