##// END OF EJS Templates
Fix problems with multiline doctests and add docs about testing....
Fernando Perez -
Show More
@@ -41,7 +41,6 b" EXCLUDE = ['IPython/external/',"
41 'IPython/Extensions/clearcmd',
41 'IPython/Extensions/clearcmd',
42 'IPython/Extensions/PhysicalQIn',
42 'IPython/Extensions/PhysicalQIn',
43 'IPython/Extensions/scitedirector',
43 'IPython/Extensions/scitedirector',
44 'IPython/testing/plugin',
45 ]
44 ]
46
45
47 #-----------------------------------------------------------------------------
46 #-----------------------------------------------------------------------------
@@ -29,9 +29,6 b' def ipfunc():'
29
29
30 In [1]: import os
30 In [1]: import os
31
31
32 In [2]: cd /
33 /
34
35 In [3]: 2+3
32 In [3]: 2+3
36 Out[3]: 5
33 Out[3]: 5
37
34
@@ -392,7 +392,6 b' class DocTestCase(doctests.DocTestCase):'
392 self._dt_test.globs = _ip.IP.user_ns
392 self._dt_test.globs = _ip.IP.user_ns
393
393
394 doctests.DocTestCase.setUp(self)
394 doctests.DocTestCase.setUp(self)
395
396
395
397
396
398 # A simple subclassing of the original with a different class name, so we can
397 # A simple subclassing of the original with a different class name, so we can
@@ -464,7 +463,11 b' class IPDocTestParser(doctest.DocTestParser):'
464 """Convert input IPython source into valid Python."""
463 """Convert input IPython source into valid Python."""
465 out = []
464 out = []
466 newline = out.append
465 newline = out.append
467 for lnum,line in enumerate(source.splitlines()):
466 #print 'IPSRC:\n',source,'\n###' # dbg
467 # The input source must be first stripped of all bracketing whitespace
468 # and turned into lines, so it looks to the parser like regular user
469 # input
470 for lnum,line in enumerate(source.strip().splitlines()):
468 newline(_ip.IP.prefilter(line,lnum>0))
471 newline(_ip.IP.prefilter(line,lnum>0))
469 newline('') # ensure a closing newline, needed by doctest
472 newline('') # ensure a closing newline, needed by doctest
470 #print "PYSRC:", '\n'.join(out) # dbg
473 #print "PYSRC:", '\n'.join(out) # dbg
@@ -3,6 +3,7 b''
3
3
4 import nose.tools as nt
4 import nose.tools as nt
5
5
6
6 def test_reset():
7 def test_reset():
7 """reset must clear most namespaces."""
8 """reset must clear most namespaces."""
8 ip = _ip.IP
9 ip = _ip.IP
@@ -283,6 +283,39 b' installed with IPython::'
283
283
284 This command runs Nose with the proper options and extensions.
284 This command runs Nose with the proper options and extensions.
285
285
286 A few tips for writing tests:
287
288 * You can use IPython examples in your docstrings, including all IPython
289 prompts. Rather than repeating it all here, see the files
290 :file:`dtexample.py` and :file:`test_ipdoctest.py` in the
291 :mod:`IPython.testing.plugin` module for examples of how you can use plain
292 Python or IPython prompts, and what to do with examples whose output could be
293 partly or completely random.
294
295 * Use the decorators shipped in the :mod:`IPython.testing` package to tag tests
296 that may be platform-specific or otherwise may have restrictions.
297
298 * If a test isn't safe to run inside the main nose process (e.g. because it
299 loads a GUI toolkit), consider running it in a subprocess and capturing its
300 output for evaluation and test decision later. Here is an example of how to
301 do it, by relying on the builtin ``_ip`` object that contains the public
302 IPython api as defined in :mod:`IPython.ipapi`::
303
304 def test_obj_del():
305 """Test that object's __del__ methods are called on exit."""
306 test_dir = os.path.dirname(__file__)
307 del_file = os.path.join(test_dir,'obj_del.py')
308 out = _ip.IP.getoutput('ipython %s' % del_file)
309 nt.assert_equals(out,'object A deleted')
310
311
312 * In a file named ``test_X``, functions whose only test is their docstring (as
313 a doctest) and which have no test functionality of their own, should be
314 called *doctest_foo* instead of *test_foo*, otherwise they get double-counted
315 (the empty function call is counted as a test, which just inflates tests
316 numbers artificially). This restriction does not apply to functions in files
317 with other names, due to how Nose discovers tests.
318
286 .. _devel_config:
319 .. _devel_config:
287
320
288 Release checklist
321 Release checklist
General Comments 0
You need to be logged in to leave comments. Login now