##// END OF EJS Templates
Fix doctest support: now running scripts that invoke the various doctest...
fperez -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Release data for the IPython project.
2 """Release data for the IPython project.
3
3
4 $Id: Release.py 2446 2007-06-14 22:30:58Z vivainio $"""
4 $Id: Release.py 2602 2007-08-12 22:45:38Z fperez $"""
5
5
6 #*****************************************************************************
6 #*****************************************************************************
7 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
7 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -22,7 +22,7 b" name = 'ipython'"
22 # because bdist_rpm does not accept dashes (an RPM) convention, and
22 # because bdist_rpm does not accept dashes (an RPM) convention, and
23 # bdist_deb does not accept underscores (a Debian convention).
23 # bdist_deb does not accept underscores (a Debian convention).
24
24
25 revision = '2445'
25 revision = '2601'
26
26
27 version = '0.8.2.svn.r' + revision.rstrip('M')
27 version = '0.8.2.svn.r' + revision.rstrip('M')
28
28
@@ -5,7 +5,7 b' General purpose utilities.'
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
5 This is a grab-bag of stuff I find useful in most programs I write. Some of
6 these things are also convenient when working at the command line.
6 these things are also convenient when working at the command line.
7
7
8 $Id: genutils.py 2577 2007-08-02 23:50:02Z fperez $"""
8 $Id: genutils.py 2602 2007-08-12 22:45:38Z fperez $"""
9
9
10 #*****************************************************************************
10 #*****************************************************************************
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
11 # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu>
@@ -799,6 +799,30 b' def flag_calls(func):'
799 return wrapper
799 return wrapper
800
800
801 #----------------------------------------------------------------------------
801 #----------------------------------------------------------------------------
802 def dhook_wrap(func,*a,**k):
803 """Wrap a function call in a sys.displayhook controller.
804
805 Returns a wrapper around func which calls func, with all its arguments and
806 keywords unmodified, using the default sys.displayhook. Since IPython
807 modifies sys.displayhook, it breaks the behavior of certain systems that
808 rely on the default behavior, notably doctest.
809 """
810
811 def f(*a,**k):
812
813 dhook_s = sys.displayhook
814 sys.displayhook = sys.__displayhook__
815 try:
816 out = func(*a,**k)
817 finally:
818 sys.displayhook = dhook_s
819
820 return out
821
822 f.__doc__ = func.__doc__
823 return f
824
825 #----------------------------------------------------------------------------
802 class HomeDirError(Error):
826 class HomeDirError(Error):
803 pass
827 pass
804
828
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.'
6
6
7 This file contains all the classes and helper functions specific to IPython.
7 This file contains all the classes and helper functions specific to IPython.
8
8
9 $Id: iplib.py 2596 2007-08-08 11:41:01Z vivainio $
9 $Id: iplib.py 2602 2007-08-12 22:45:38Z fperez $
10 """
10 """
11
11
12 #*****************************************************************************
12 #*****************************************************************************
@@ -41,6 +41,7 b' import StringIO'
41 import bdb
41 import bdb
42 import cPickle as pickle
42 import cPickle as pickle
43 import codeop
43 import codeop
44 import doctest
44 import exceptions
45 import exceptions
45 import glob
46 import glob
46 import inspect
47 import inspect
@@ -678,6 +679,14 b' class InteractiveShell(object,Magic):'
678 self.sys_displayhook = sys.displayhook
679 self.sys_displayhook = sys.displayhook
679 sys.displayhook = self.outputcache
680 sys.displayhook = self.outputcache
680
681
682 # Monkeypatch doctest so that its core test runner method is protected
683 # from IPython's modified displayhook. Doctest expects the default
684 # displayhook behavior deep down, so our modification breaks it
685 # completely. For this reason, a hard monkeypatch seems like a
686 # reasonable solution rather than asking users to manually use a
687 # different doctest runner when under IPython.
688 doctest.DocTestRunner.run = dhook_wrap(doctest.DocTestRunner.run)
689
681 # Set user colors (don't do it in the constructor above so that it
690 # Set user colors (don't do it in the constructor above so that it
682 # doesn't crash if colors option is invalid)
691 # doesn't crash if colors option is invalid)
683 self.magic_colors(rc.colors)
692 self.magic_colors(rc.colors)
@@ -1,3 +1,9 b''
1 2007-08-12 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * IPython/iplib.py (InteractiveShell.post_config_initialization):
4 fix problems with doctests failing when run inside IPython due to
5 IPython's modifications of sys.displayhook.
6
1 2007-8-9 Fernando Perez <fperez@planck.colorado.edu>
7 2007-8-9 Fernando Perez <fperez@planck.colorado.edu>
2
8
3 * IPython/ipapi.py (to_user_ns): update to accept a dict as well as
9 * IPython/ipapi.py (to_user_ns): update to accept a dict as well as
@@ -509,6 +509,21 b' profile'
509 ') convenient for rapid interactive work.
509 ') convenient for rapid interactive work.
510 \end_layout
510 \end_layout
511
511
512 \begin_layout Itemize
513 Doctest support.
514 The special
515 \family typewriter
516 %doctest_mode
517 \family default
518 command toggles a mode that allows you to paste existing doctests (with
519 leading `
520 \family typewriter
521 >>>
522 \family default
523 ' prompts and whitespace) and uses doctest-compatible prompts and output,
524 so you can use IPython sessions as doctest code.
525 \end_layout
526
512 \begin_layout Subsection
527 \begin_layout Subsection
513 Portability and Python requirements
528 Portability and Python requirements
514 \end_layout
529 \end_layout
@@ -2646,6 +2661,31 b' Use the IPython.demo.Demo class to load any Python script as an interactive'
2646 for more.
2661 for more.
2647 \end_layout
2662 \end_layout
2648
2663
2664 \begin_layout Itemize
2665 Run your doctests from within IPython for development and debugging.
2666 The special
2667 \family typewriter
2668 %doctest_mode
2669 \family default
2670 command toggles a mode where the prompt, output and exceptions display
2671 matches as closely as possible that of the default Python interpreter.
2672 In addition, this mode allows you to directly paste in code that contains
2673 leading `
2674 \family typewriter
2675 >>>
2676 \family default
2677 ' prompts, even if they have extra leading whitespace (as is common in doctest
2678 files).
2679 This combined with the `
2680 \family typewriter
2681 %history -t
2682 \family default
2683 n' call to see your translated history (with these extra prompts removed
2684 and no line numbers) allows for an easy doctest workflow, where you can
2685 go from doctest to interactive execution to pasting into valid Python code
2686 as needed.
2687 \end_layout
2688
2649 \begin_layout Subsection
2689 \begin_layout Subsection
2650 Source code handling tips
2690 Source code handling tips
2651 \end_layout
2691 \end_layout
General Comments 0
You need to be logged in to leave comments. Login now