##// END OF EJS Templates
Checkpoint before merging with upstream
Fernando Perez -
Show More
@@ -1010,7 +1010,7 b' class InteractiveShell(object,Magic):'
1010 hello
1010 hello
1011
1011
1012 In [10]: _ip.IP.complete('x.l')
1012 In [10]: _ip.IP.complete('x.l')
1013 Out[10]: ['x.ljust', 'x.lower', 'x.lstrip'] # random
1013 Out[10]: ['x.ljust', 'x.lower', 'x.lstrip'] # randomX
1014 """
1014 """
1015
1015
1016 complete = self.Completer.complete
1016 complete = self.Completer.complete
@@ -5,47 +5,59 b' PREFIX=~/tmp/local'
5 NOSE0=nosetests -vs --with-doctest --doctest-tests
5 NOSE0=nosetests -vs --with-doctest --doctest-tests
6 NOSE=nosetests -vvs --with-ipdoctest --doctest-tests --doctest-extension=txt
6 NOSE=nosetests -vvs --with-ipdoctest --doctest-tests --doctest-extension=txt
7
7
8 #--with-color
9
10 SRC=ipdoctest.py setup.py ../decorators.py
8 SRC=ipdoctest.py setup.py ../decorators.py
11
9
10 # Default target for clean 'make'
11 default: iplib
12
13 # The actual plugin installation
12 plugin: IPython_doctest_plugin.egg-info
14 plugin: IPython_doctest_plugin.egg-info
13
15
16 # Simple targets that test one thing
17 simple: plugin simple.py
18 $(NOSE) simple.py
19
14 dtest: plugin dtexample.py
20 dtest: plugin dtexample.py
15 $(NOSE) dtexample.py
21 $(NOSE) dtexample.py
16
22
17 # Note: this test is double counting!!!
23 rtest: plugin test_refs.py
18 rtest: plugin dtexample.py
19 $(NOSE) test_refs.py
24 $(NOSE) test_refs.py
20
25
21 std: plugin
22 nosetests -vs --with-doctest --doctest-tests IPython.strdispatch
23 $(NOSE) IPython.strdispatch
24
25 test: plugin dtexample.py
26 test: plugin dtexample.py
26 $(NOSE) dtexample.py test*.py test*.txt
27 $(NOSE) dtexample.py test*.py test*.txt
27
28
28 deb: plugin dtexample.py
29 deb: plugin dtexample.py
29 $(NOSE) test_combo.txt
30 $(NOSE) test_combo.txt
30
31
31 iptest: plugin
32 # IPython tests
32 $(NOSE) IPython
33
34 deco:
33 deco:
35 $(NOSE0) IPython.testing.decorators
34 $(NOSE0) -x IPython.testing.decorators
36
35
37 mtest: plugin
36 magic: plugin
38 $(NOSE) -x IPython.Magic
37 $(NOSE) -x IPython.Magic
39
38
40 ipipe: plugin
39 ipipe: plugin
41 $(NOSE) -x IPython.Extensions.ipipe
40 $(NOSE) -x IPython.Extensions.ipipe
42
41
43 sr: rtest std
42 iplib: plugin
43 $(NOSE) -x IPython.iplib
44
45 strd: plugin
46 nosetests -vs --with-doctest --doctest-tests IPython.strdispatch
47 $(NOSE) IPython.strdispatch
48
49 # All of ipython itself
50 ipython: plugin
51 $(NOSE) IPython
52
53 # Combined targets
54 sr: rtest strd
44
55
45 base: dtest rtest test std deco
56 base: dtest rtest test strd deco
46
57
47 all: base iptest
58 all: base ipython
48
59
60 # Main plugin and cleanup
49 IPython_doctest_plugin.egg-info: $(SRC)
61 IPython_doctest_plugin.egg-info: $(SRC)
50 python setup.py install --prefix=$(PREFIX)
62 python setup.py install --prefix=$(PREFIX)
51 touch $@
63 touch $@
@@ -58,6 +58,12 b' def ipfunc():'
58 numbered history of _NN outputs, since those won't exist under the
58 numbered history of _NN outputs, since those won't exist under the
59 doctest environment:
59 doctest environment:
60
60
61 In [7]: 'hi'
62 Out[7]: 'hi'
63
64 In [8]: print repr(_)
65 'hi'
66
61 In [7]: 3+4
67 In [7]: 3+4
62 Out[7]: 7
68 Out[7]: 7
63
69
@@ -94,6 +94,28 b' def _run_ns_sync(self,arg_s,runner=None):'
94 return out
94 return out
95
95
96
96
97 # XXX1 - namespace handling
98 class ncdict(dict):
99 def __init__(self,*a):
100 dict.__init__(self,*a)
101 self._savedict = {}
102
103 def copy(self):
104 return self
105
106 def clear(self):
107 import IPython
108
109 print 'NCDICT - clear' # dbg
110 dict.clear(self)
111 self.update(IPython.ipapi.make_user_ns())
112 self.update(self._savedict)
113
114 def remember(self,adict):
115 self._savedict = adict
116
117 #class ncdict(dict): pass
118
97 def start_ipython():
119 def start_ipython():
98 """Start a global IPython shell, which we need for IPython-specific syntax.
120 """Start a global IPython shell, which we need for IPython-specific syntax.
99 """
121 """
@@ -117,7 +139,10 b' def start_ipython():'
117 _main = sys.modules.get('__main__')
139 _main = sys.modules.get('__main__')
118
140
119 # Start IPython instance. We customize it to start with minimal frills.
141 # Start IPython instance. We customize it to start with minimal frills.
120 IPython.Shell.IPShell(['--classic','--noterm_title'])
142 user_ns = IPython.ipapi.make_user_ns(ncdict())
143
144 IPython.Shell.IPShell(['--classic','--noterm_title'],
145 user_ns)
121
146
122 # Deactivate the various python system hooks added by ipython for
147 # Deactivate the various python system hooks added by ipython for
123 # interactive convenience so we don't confuse the doctest system
148 # interactive convenience so we don't confuse the doctest system
@@ -250,6 +275,85 b' class DocTestFinder(doctest.DocTestFinder):'
250 globs, seen)
275 globs, seen)
251
276
252
277
278 # XXX1 - namespace handling
279 def Xfind(self, obj, name=None, module=None, globs=None, extraglobs=None):
280 """
281 Return a list of the DocTests that are defined by the given
282 object's docstring, or by any of its contained objects'
283 docstrings.
284
285 The optional parameter `module` is the module that contains
286 the given object. If the module is not specified or is None, then
287 the test finder will attempt to automatically determine the
288 correct module. The object's module is used:
289
290 - As a default namespace, if `globs` is not specified.
291 - To prevent the DocTestFinder from extracting DocTests
292 from objects that are imported from other modules.
293 - To find the name of the file containing the object.
294 - To help find the line number of the object within its
295 file.
296
297 Contained objects whose module does not match `module` are ignored.
298
299 If `module` is False, no attempt to find the module will be made.
300 This is obscure, of use mostly in tests: if `module` is False, or
301 is None but cannot be found automatically, then all objects are
302 considered to belong to the (non-existent) module, so all contained
303 objects will (recursively) be searched for doctests.
304
305 The globals for each DocTest is formed by combining `globs`
306 and `extraglobs` (bindings in `extraglobs` override bindings
307 in `globs`). A new copy of the globals dictionary is created
308 for each DocTest. If `globs` is not specified, then it
309 defaults to the module's `__dict__`, if specified, or {}
310 otherwise. If `extraglobs` is not specified, then it defaults
311 to {}.
312
313 """
314
315 # Find the module that contains the given object (if obj is
316 # a module, then module=obj.). Note: this may fail, in which
317 # case module will be None.
318 if module is False:
319 module = None
320 elif module is None:
321 module = inspect.getmodule(obj)
322
323 # always build our own globals
324 if globs is None:
325 if module is None:
326 globs = {}
327 else:
328 globs = module.__dict__.copy()
329 else:
330 globs.update(module.__dict__.copy())
331
332 print 'globs is:',globs.keys()
333
334 if extraglobs is not None:
335 globs.update(extraglobs)
336
337 try:
338 globs.remember(module.__dict__)
339 except:
340 pass
341
342 ## # Initialize globals, and merge in extraglobs.
343 ## if globs is None:
344 ## if module is None:
345 ## globs = {}
346 ## else:
347 ## globs = module.__dict__.copy()
348 ## else:
349 ## globs = globs.copy()
350 ## if extraglobs is not None:
351 ## globs.update(extraglobs)
352
353 return doctest.DocTestFinder.find(self,obj,name,module,globs,
354 extraglobs)
355
356
253 class IPDoctestOutputChecker(doctest.OutputChecker):
357 class IPDoctestOutputChecker(doctest.OutputChecker):
254 """Second-chance checker with support for random tests.
358 """Second-chance checker with support for random tests.
255
359
@@ -342,6 +446,12 b' class DocTestCase(doctests.DocTestCase):'
342 if failures:
446 if failures:
343 raise self.failureException(self.format_failure(new.getvalue()))
447 raise self.failureException(self.format_failure(new.getvalue()))
344
448
449 # XXX1 - namespace handling
450 def XtearDown(self):
451 print '!! teardown!' # dbg
452 doctests.DocTestCase.tearDown(self)
453
454
345
455
346 # A simple subclassing of the original with a different class name, so we can
456 # A simple subclassing of the original with a different class name, so we can
347 # distinguish and treat differently IPython examples from pure python ones.
457 # distinguish and treat differently IPython examples from pure python ones.
@@ -749,5 +859,9 b' class IPythonDoctest(ExtensionDoctest):'
749 self.extension = tolist(options.doctestExtension)
859 self.extension = tolist(options.doctestExtension)
750 self.parser = IPDocTestParser()
860 self.parser = IPDocTestParser()
751 self.finder = DocTestFinder(parser=self.parser)
861 self.finder = DocTestFinder(parser=self.parser)
862
863 # XXX1 - namespace handling
752 self.globs = None
864 self.globs = None
865 #self.globs = _ip.IP.user_ns
866
753 self.extraglobs = None
867 self.extraglobs = None
General Comments 0
You need to be logged in to leave comments. Login now