Show More
@@ -0,0 +1,137 b'' | |||||
|
1 | """Doctest-related utilities for IPython. | |||
|
2 | ||||
|
3 | For most common uses, all you should need to run is:: | |||
|
4 | ||||
|
5 | from IPython.dtutils import idoctest | |||
|
6 | ||||
|
7 | See the idoctest docstring below for usage details. | |||
|
8 | """ | |||
|
9 | ||||
|
10 | import doctest | |||
|
11 | import sys | |||
|
12 | ||||
|
13 | import IPython.ipapi | |||
|
14 | ip = IPython.ipapi.get() | |||
|
15 | ||||
|
16 | def rundoctest(text,ns=None,eraise=False): | |||
|
17 | """Run a the input source as a doctest, in the caller's namespace. | |||
|
18 | ||||
|
19 | :Parameters: | |||
|
20 | text : str | |||
|
21 | Source to execute. | |||
|
22 | ||||
|
23 | :Keywords: | |||
|
24 | ns : dict (None) | |||
|
25 | Namespace where the code should be executed. If not given, the | |||
|
26 | caller's locals and globals are used. | |||
|
27 | eraise : bool (False) | |||
|
28 | If true, immediately raise any exceptions instead of reporting them at | |||
|
29 | the end. This allows you to then do interactive debugging via | |||
|
30 | IPython's facilities (use %debug after the fact, or with %pdb for | |||
|
31 | automatic activation). | |||
|
32 | """ | |||
|
33 | ||||
|
34 | name = 'interactive doctest' | |||
|
35 | filename = '<IPython console>' | |||
|
36 | ||||
|
37 | if eraise: | |||
|
38 | runner = doctest.DebugRunner() | |||
|
39 | else: | |||
|
40 | runner = doctest.DocTestRunner() | |||
|
41 | ||||
|
42 | parser = doctest.DocTestParser() | |||
|
43 | if ns is None: | |||
|
44 | f = sys._getframe(1) | |||
|
45 | ns = f.f_globals.copy() | |||
|
46 | ns.update(f.f_locals) | |||
|
47 | ||||
|
48 | test = parser.get_doctest(text,ns,name,filename,0) | |||
|
49 | runner.run(test) | |||
|
50 | runner.summarize(True) | |||
|
51 | ||||
|
52 | ||||
|
53 | def idoctest(ns=None,eraise=False): | |||
|
54 | """Interactively prompt for input and run it as a doctest. | |||
|
55 | ||||
|
56 | To finish entering input, enter two blank lines or Ctrl-D (EOF). If you | |||
|
57 | use Ctrl-C, the example is aborted and all input discarded. | |||
|
58 | ||||
|
59 | :Keywords: | |||
|
60 | ns : dict (None) | |||
|
61 | Namespace where the code should be executed. If not given, the IPython | |||
|
62 | interactive namespace is used. | |||
|
63 | eraise : bool (False) | |||
|
64 | If true, immediately raise any exceptions instead of reporting them at | |||
|
65 | the end. This allows you to then do interactive debugging via | |||
|
66 | IPython's facilities (use %debug after the fact, or with %pdb for | |||
|
67 | automatic activation). | |||
|
68 | end_mark : str ('--') | |||
|
69 | String to explicitly indicate the end of input. | |||
|
70 | ||||
|
71 | """ | |||
|
72 | ||||
|
73 | inlines = [] | |||
|
74 | empty_lines = 0 # count consecutive empty lines | |||
|
75 | run_test = True | |||
|
76 | ||||
|
77 | if ns is None: | |||
|
78 | ns = ip.user_ns | |||
|
79 | ||||
|
80 | ip.IP.savehist() | |||
|
81 | try: | |||
|
82 | while True: | |||
|
83 | line = raw_input() | |||
|
84 | if not line or line.isspace(): | |||
|
85 | empty_lines += 1 | |||
|
86 | else: | |||
|
87 | empty_lines = 0 | |||
|
88 | ||||
|
89 | if empty_lines>=2: | |||
|
90 | break | |||
|
91 | ||||
|
92 | inlines.append(line) | |||
|
93 | except EOFError: | |||
|
94 | pass | |||
|
95 | except KeyboardInterrupt: | |||
|
96 | print "KeyboardInterrupt - Discarding input." | |||
|
97 | run_test = False | |||
|
98 | ||||
|
99 | ip.IP.reloadhist() | |||
|
100 | ||||
|
101 | if run_test: | |||
|
102 | # Extra blank line at the end to ensure that the final docstring has a | |||
|
103 | # closing newline | |||
|
104 | inlines.append('') | |||
|
105 | rundoctest('\n'.join(inlines),ns,eraise) | |||
|
106 | ||||
|
107 | ||||
|
108 | # For debugging of this module itself. | |||
|
109 | if __name__ == "__main__": | |||
|
110 | t = """ | |||
|
111 | >>> for i in range(10): | |||
|
112 | ... print i, | |||
|
113 | ... | |||
|
114 | 0 1 2 3 4 5 6 7 8 9 | |||
|
115 | """ | |||
|
116 | ||||
|
117 | t2 = """ | |||
|
118 | A simple example:: | |||
|
119 | ||||
|
120 | >>> for i in range(10): | |||
|
121 | ... print i, | |||
|
122 | ... | |||
|
123 | 0 1 2 3 4 5 6 7 8 9 | |||
|
124 | ||||
|
125 | Some more details:: | |||
|
126 | ||||
|
127 | >>> print "hello" | |||
|
128 | hello | |||
|
129 | """ | |||
|
130 | ||||
|
131 | t3 = """ | |||
|
132 | A failing example:: | |||
|
133 | ||||
|
134 | >>> x=1 | |||
|
135 | >>> x+1 | |||
|
136 | 3 | |||
|
137 | """ |
@@ -1,7 +1,7 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Magic functions for InteractiveShell. |
|
2 | """Magic functions for InteractiveShell. | |
3 |
|
3 | |||
4 |
$Id: Magic.py 28 |
|
4 | $Id: Magic.py 2899 2007-12-28 08:32:59Z fperez $""" | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and | |
@@ -1566,7 +1566,6 b' Currently the magic system has the following functions:\\n"""' | |||||
1566 |
|
1566 | |||
1567 | stats = None |
|
1567 | stats = None | |
1568 | try: |
|
1568 | try: | |
1569 | if self.shell.has_readline: |
|
|||
1570 |
|
|
1569 | self.shell.savehist() | |
1571 |
|
1570 | |||
1572 | if opts.has_key('p'): |
|
1571 | if opts.has_key('p'): |
@@ -2,7 +2,7 b'' | |||||
2 | """ |
|
2 | """ | |
3 | Classes for handling input/output prompts. |
|
3 | Classes for handling input/output prompts. | |
4 |
|
4 | |||
5 |
$Id: Prompts.py 28 |
|
5 | $Id: Prompts.py 2899 2007-12-28 08:32:59Z fperez $""" | |
6 |
|
6 | |||
7 | #***************************************************************************** |
|
7 | #***************************************************************************** | |
8 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> |
|
8 | # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> | |
@@ -323,6 +323,13 b' class BasePrompt(object):' | |||||
323 | else: |
|
323 | else: | |
324 | return os.sep |
|
324 | return os.sep | |
325 |
|
325 | |||
|
326 | def __nonzero__(self): | |||
|
327 | """Implement boolean behavior. | |||
|
328 | ||||
|
329 | Checks whether the p_str attribute is non-empty""" | |||
|
330 | ||||
|
331 | return bool(self.p_template) | |||
|
332 | ||||
326 | class Prompt1(BasePrompt): |
|
333 | class Prompt1(BasePrompt): | |
327 | """Input interactive prompt similar to Mathematica's.""" |
|
334 | """Input interactive prompt similar to Mathematica's.""" | |
328 |
|
335 |
@@ -32,7 +32,7 b" ip.set_hook('editor', calljed)" | |||||
32 | You can then enable the functionality by doing 'import myiphooks' |
|
32 | You can then enable the functionality by doing 'import myiphooks' | |
33 | somewhere in your configuration files or ipython command line. |
|
33 | somewhere in your configuration files or ipython command line. | |
34 |
|
34 | |||
35 |
$Id: hooks.py |
|
35 | $Id: hooks.py 2899 2007-12-28 08:32:59Z fperez $""" | |
36 |
|
36 | |||
37 | #***************************************************************************** |
|
37 | #***************************************************************************** | |
38 | # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu> |
|
38 | # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu> | |
@@ -213,5 +213,3 b' def generate_prompt(self, is_continuation):' | |||||
213 | def generate_output_prompt(self): |
|
213 | def generate_output_prompt(self): | |
214 | ip = self.api |
|
214 | ip = self.api | |
215 | return str(ip.IP.outputcache.prompt_out) |
|
215 | return str(ip.IP.outputcache.prompt_out) | |
216 |
|
||||
217 | No newline at end of file |
|
@@ -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 289 |
|
9 | $Id: iplib.py 2899 2007-12-28 08:32:59Z fperez $ | |
10 | """ |
|
10 | """ | |
11 |
|
11 | |||
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
@@ -1247,6 +1247,10 b' want to merge them back into the new files.""" % locals()' | |||||
1247 |
|
1247 | |||
1248 | def savehist(self): |
|
1248 | def savehist(self): | |
1249 | """Save input history to a file (via readline library).""" |
|
1249 | """Save input history to a file (via readline library).""" | |
|
1250 | ||||
|
1251 | if not self.has_readline: | |||
|
1252 | return | |||
|
1253 | ||||
1250 | try: |
|
1254 | try: | |
1251 | self.readline.write_history_file(self.histfile) |
|
1255 | self.readline.write_history_file(self.histfile) | |
1252 | except: |
|
1256 | except: |
@@ -6,7 +6,7 b' Requires Python 2.1 or better.' | |||||
6 |
|
6 | |||
7 | This file contains the main make_IPython() starter function. |
|
7 | This file contains the main make_IPython() starter function. | |
8 |
|
8 | |||
9 |
$Id: ipmaker.py 28 |
|
9 | $Id: ipmaker.py 2899 2007-12-28 08:32:59Z fperez $""" | |
10 |
|
10 | |||
11 | #***************************************************************************** |
|
11 | #***************************************************************************** | |
12 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> |
|
12 | # Copyright (C) 2001-2006 Fernando Perez. <fperez@colorado.edu> | |
@@ -190,25 +190,26 b" object? -> Details about 'object'. ?object also works, ?? prints more." | |||||
190 | autoindent = 0, |
|
190 | autoindent = 0, | |
191 | automagic = 1, |
|
191 | automagic = 1, | |
192 | banner = 1, |
|
192 | banner = 1, | |
193 | cache_size = 1000, |
|
|||
194 | c = '', |
|
193 | c = '', | |
|
194 | cache_size = 1000, | |||
195 | classic = 0, |
|
195 | classic = 0, | |
196 | colors = 'NoColor', |
|
|||
197 | color_info = 0, |
|
196 | color_info = 0, | |
|
197 | colors = 'NoColor', | |||
198 | confirm_exit = 1, |
|
198 | confirm_exit = 1, | |
199 | debug = 0, |
|
199 | debug = 0, | |
200 | deep_reload = 0, |
|
200 | deep_reload = 0, | |
201 | editor = '0', |
|
201 | editor = '0', | |
|
202 | gthread = 0, | |||
202 | help = 0, |
|
203 | help = 0, | |
203 | interact = 1, |
|
204 | interact = 1, | |
204 | ipythondir = ipythondir_def, |
|
205 | ipythondir = ipythondir_def, | |
205 | log = 0, |
|
206 | log = 0, | |
206 | logfile = '', |
|
207 | logfile = '', | |
207 | logplay = '', |
|
208 | logplay = '', | |
208 | multi_line_specials = 1, |
|
|||
209 | messages = 1, |
|
209 | messages = 1, | |
210 |
|
|
210 | multi_line_specials = 1, | |
211 | nosep = 0, |
|
211 | nosep = 0, | |
|
212 | object_info_string_level = 0, | |||
212 | pdb = 0, |
|
213 | pdb = 0, | |
213 | pprint = 0, |
|
214 | pprint = 0, | |
214 | profile = '', |
|
215 | profile = '', | |
@@ -216,31 +217,30 b" object? -> Details about 'object'. ?object also works, ?? prints more." | |||||
216 | prompt_in2 = ' .\\D.: ', |
|
217 | prompt_in2 = ' .\\D.: ', | |
217 | prompt_out = 'Out[\\#]: ', |
|
218 | prompt_out = 'Out[\\#]: ', | |
218 | prompts_pad_left = 1, |
|
219 | prompts_pad_left = 1, | |
|
220 | pylab = 0, | |||
219 | pylab_import_all = 1, |
|
221 | pylab_import_all = 1, | |
220 |
q |
|
222 | q4thread = 0, | |
|
223 | qthread = 0, | |||
221 | quick = 0, |
|
224 | quick = 0, | |
|
225 | quiet = 0, | |||
|
226 | rcfile = 'ipythonrc' + rc_suffix, | |||
222 | readline = 1, |
|
227 | readline = 1, | |
223 | readline_merge_completions = 1, |
|
228 | readline_merge_completions = 1, | |
224 | readline_omit__names = 0, |
|
229 | readline_omit__names = 0, | |
225 | rcfile = 'ipythonrc' + rc_suffix, |
|
|||
226 | screen_length = 0, |
|
230 | screen_length = 0, | |
227 | separate_in = '\n', |
|
231 | separate_in = '\n', | |
228 | separate_out = '\n', |
|
232 | separate_out = '\n', | |
229 | separate_out2 = '', |
|
233 | separate_out2 = '', | |
230 | system_header = 'IPython system call: ', |
|
234 | system_header = 'IPython system call: ', | |
231 | system_verbose = 0, |
|
235 | system_verbose = 0, | |
232 | gthread = 0, |
|
|||
233 | qthread = 0, |
|
|||
234 | q4thread = 0, |
|
|||
235 | wthread = 0, |
|
|||
236 | pylab = 0, |
|
|||
237 | term_title = 1, |
|
236 | term_title = 1, | |
238 | tk = 0, |
|
237 | tk = 0, | |
239 | upgrade = 0, |
|
238 | upgrade = 0, | |
240 | Version = 0, |
|
239 | Version = 0, | |
241 | xmode = 'Verbose', |
|
|||
242 | wildcards_case_sensitive = 1, |
|
240 | wildcards_case_sensitive = 1, | |
|
241 | wthread = 0, | |||
243 | wxversion = '0', |
|
242 | wxversion = '0', | |
|
243 | xmode = 'Context', | |||
244 | magic_docstrings = 0, # undocumented, for doc generation |
|
244 | magic_docstrings = 0, # undocumented, for doc generation | |
245 | ) |
|
245 | ) | |
246 |
|
246 |
@@ -1,9 +1,21 b'' | |||||
|
1 | 2007-12-28 Fernando Perez <Fernando.Perez@colorado.edu> | |||
|
2 | ||||
|
3 | * IPython/dtutils.py: Add utilities for interactively running | |||
|
4 | doctests. Still needs work to more easily handle the namespace of | |||
|
5 | the package one may be working on, but the basics are in place. | |||
|
6 | ||||
1 | 2007-12-20 Ville Vainio <vivainio@gmail.com> |
|
7 | 2007-12-20 Ville Vainio <vivainio@gmail.com> | |
2 |
|
8 | |||
3 | * completer.py, generics.py(complete_object): Allow |
|
9 | * completer.py, generics.py(complete_object): Allow | |
4 | custom complers based on python objects via simplegeneric. |
|
10 | custom complers based on python objects via simplegeneric. | |
5 | See generics.py / my_demo_complete_object |
|
11 | See generics.py / my_demo_complete_object | |
6 |
|
12 | |||
|
13 | 2007-12-13 Fernando Perez <Fernando.Perez@colorado.edu> | |||
|
14 | ||||
|
15 | * IPython/Prompts.py (BasePrompt.__nonzero__): add proper boolean | |||
|
16 | behavior to prompt objects, useful for display hooks to adjust | |||
|
17 | themselves depending on whether prompts will be there or not. | |||
|
18 | ||||
7 | 2007-12-13 Ville Vainio <vivainio@gmail.com> |
|
19 | 2007-12-13 Ville Vainio <vivainio@gmail.com> | |
8 |
|
20 | |||
9 | * iplib.py(raw_input): unix readline does not allow unicode in |
|
21 | * iplib.py(raw_input): unix readline does not allow unicode in |
General Comments 0
You need to be logged in to leave comments.
Login now