##// END OF EJS Templates
Add information about our testing system, test writing tips, etc.
Fernando Perez -
Show More
@@ -17,7 +17,29 b' How to contribute to IPython'
17
17
18 IPython development is done using Bazaar [Bazaar]_ and Launchpad [Launchpad]_.
18 IPython development is done using Bazaar [Bazaar]_ and Launchpad [Launchpad]_.
19 This makes it easy for people to contribute to the development of IPython.
19 This makes it easy for people to contribute to the development of IPython.
20 Here is a sketch of how to get going.
20 There are several ways in which you can join in.
21
22 If you have a small change that you want to send to the team, you can edit your
23 bazaar checkout of IPython (see below) in-place, and ask bazaar for the
24 differences::
25
26 $ cd /path/to/your/copy/of/ipython
27 $ bzr diff > my_fixes.diff
28
29 This produces a patch file with your fixes, which we can apply to the source
30 tree. This file should then be attached to a ticket in our `bug tracker
31 <https://bugs.launchpad.net/ipython>`_, indicating what it does.
32
33 This model of creating small, self-contained patches works very well and there
34 are open source projects that do their entire development this way. However,
35 in IPython we have found that for tracking larger changes, making use of
36 bazaar's full capabilities in conjunction with Launchpad's code hosting
37 services makes for a much better experience.
38
39 Making your own branch of IPython allows you to refine your changes over time,
40 track the development of the main team, and propose your own full version of
41 the code for others to use and review, with a minimum amount of fuss. The next
42 parts of this document will explain how to do this.
21
43
22 Install Bazaar and create a Launchpad account
44 Install Bazaar and create a Launchpad account
23 ---------------------------------------------
45 ---------------------------------------------
@@ -102,12 +124,16 b' commands::'
102 $ bzr merge ../ipython
124 $ bzr merge ../ipython
103 $ bzr commit -m "Merging changes from trunk"
125 $ bzr commit -m "Merging changes from trunk"
104
126
105 Along the way, you should also run the IPython test suite. You can do this using the :command:`iptest` command::
127 Along the way, you should also run the IPython test suite. You can do this
128 using the :command:`iptest` command (which is basically a customized version of
129 :command:`nosetests`)::
106
130
107 $ cd
131 $ cd
108 $ iptest
132 $ iptest
109
133
110 The :command:`iptest` command will also pick up and run any tests you have written.
134 The :command:`iptest` command will also pick up and run any tests you have
135 written. See :ref:`_devel_testing` for further details on the testing system.
136
111
137
112 Post your branch and request a code review
138 Post your branch and request a code review
113 ------------------------------------------
139 ------------------------------------------
@@ -151,7 +177,8 b' source tree. The documentation in this location will serve as the main source'
151 for IPython documentation and all existing documentation should be converted
177 for IPython documentation and all existing documentation should be converted
152 to this format.
178 to this format.
153
179
154 To build the final documentation, we use Sphinx [Sphinx]_. Once you have Sphinx installed, you can build the html docs yourself by doing::
180 To build the final documentation, we use Sphinx [Sphinx]_. Once you have
181 Sphinx installed, you can build the html docs yourself by doing::
155
182
156 $ cd ipython-mybranch/docs
183 $ cd ipython-mybranch/docs
157 $ make html
184 $ make html
@@ -271,35 +298,85 b' twisted reactor will be handled correctly.'
271
298
272 Each subpackage in IPython should have its own :file:`tests` directory that
299 Each subpackage in IPython should have its own :file:`tests` directory that
273 contains all of the tests for that subpackage. This allows each subpackage to
300 contains all of the tests for that subpackage. This allows each subpackage to
274 be self-contained. If a subpackage has any dependencies beyond the Python
301 be self-contained. A good convention to follow is to have a file named
275 standard library, the tests for that subpackage should be skipped if the
302 :file:`test_foo.py` for each module :file:`foo.py` in the package. This makes
276 dependencies are not found. This is very important so users don't get tests
303 it easy to organize the tests, though like most conventions, it's OK to break
277 failing simply because they don't have dependencies.
304 it if logic and common sense dictate otherwise.
305
306 If a subpackage has any dependencies beyond the Python standard library, the
307 tests for that subpackage should be skipped if the dependencies are not
308 found. This is very important so users don't get tests failing simply because
309 they don't have dependencies. We ship a set of decorators in the
310 :mod:`IPython.testing` package to tag tests that may be platform-specific or
311 otherwise may have restrictions; if the existing ones don't fit your needs, add
312 a new decorator in that location so other tests can reuse it.
278
313
279 To run the IPython test suite, use the :command:`iptest` command that is
314 To run the IPython test suite, use the :command:`iptest` command that is
280 installed with IPython::
315 installed with IPython (if you are using IPython in-place, without installing
316 it, you can find this script in the :file:`scripts` directory)::
281
317
282 $ iptest
318 $ iptest
283
319
284 This command runs Nose with the proper options and extensions.
320 This command runs Nose with the proper options and extensions. By default,
285
321 :command:`iptest` runs the entire IPython test suite (skipping tests that may
286 A few tips for writing tests:
322 be platform-specific or which depend on tools you may not have). But you can
287
323 also use it to run only one specific test file, or a specific test function.
288 * You can use IPython examples in your docstrings, including all IPython
324 For example, this will run only the :file:`test_magic` file from the test
289 prompts. Rather than repeating it all here, see the files
325 suite::
290 :file:`dtexample.py` and :file:`test_ipdoctest.py` in the
326
291 :mod:`IPython.testing.plugin` module for examples of how you can use plain
327 $ iptest IPython.tests.test_magic
292 Python or IPython prompts, and what to do with examples whose output could be
328 ----------------------------------------------------------------------
293 partly or completely random.
329 Ran 10 tests in 0.348s
294
330
295 * Use the decorators shipped in the :mod:`IPython.testing` package to tag tests
331 OK (SKIP=3)
296 that may be platform-specific or otherwise may have restrictions.
332 Deleting object: second_pass
297
333
298 * If a test isn't safe to run inside the main nose process (e.g. because it
334 while the ``path:function`` syntax allows you to select a specific function in
299 loads a GUI toolkit), consider running it in a subprocess and capturing its
335 that file to run::
300 output for evaluation and test decision later. Here is an example of how to
336
301 do it, by relying on the builtin ``_ip`` object that contains the public
337 $ iptest IPython.tests.test_magic:test_obj_del
302 IPython api as defined in :mod:`IPython.ipapi`::
338 ----------------------------------------------------------------------
339 Ran 1 test in 0.204s
340
341 OK
342
343 Since :command:`iptest` is based on nosetests, you can pass it any regular
344 nosetests option. For example, you can use ``--pdb`` or ``--pdb-failures`` to
345 automatically activate the interactive Pdb debugger on errors or failures. See
346 the nosetests documentation for further details.
347
348 A few tips for writing tests
349 ----------------------------
350
351 You can write tests either as normal test files, using all the conventions that
352 Nose recognizes, or as doctests. Note that *all* IPython functions should have
353 at least one example that serves as a doctest, whenever technically feasible.
354 However, example doctests should only be in the main docstring if they are *a
355 good example*, i.e. if they convey useful information about the function. If
356 you simply would like to write a test as a doctest, put it in a separate test
357 file and write a no-op function whose only purpose is its docstring.
358
359 Note, however, that in a file named :file:`test_X`, functions whose only test
360 is their docstring (as a doctest) and which have no test functionality of their
361 own, should be called *doctest_foo* instead of *test_foo*, otherwise they get
362 double-counted (the empty function call is counted as a test, which just
363 inflates tests numbers artificially). This restriction does not apply to
364 functions in files with other names, due to how Nose discovers tests.
365
366 You can use IPython examples in your docstrings. Those can make full use of
367 IPython functionality (magics, variable substitution, etc), but be careful to
368 keep them generic enough that they run identically on all Operating Systems.
369
370 The prompts in your doctests can be either of the plain Python ``>>>`` variety
371 or ``In [1]:`` IPython style. Since this is the IPython system, after all, we
372 encourage you to use IPython prompts throughout, unless you are illustrating a
373 specific aspect of the normal prompts (such as the ``%doctest_mode`` magic).
374
375 If a test isn't safe to run inside the main nose process (e.g. because it loads
376 a GUI toolkit), consider running it in a subprocess and capturing its output
377 for evaluation and test decision later. Here is an example of how to do it, by
378 relying on the builtin ``_ip`` object that contains the public IPython api as
379 defined in :mod:`IPython.ipapi`::
303
380
304 def test_obj_del():
381 def test_obj_del():
305 """Test that object's __del__ methods are called on exit."""
382 """Test that object's __del__ methods are called on exit."""
@@ -309,13 +386,31 b' A few tips for writing tests:'
309 nt.assert_equals(out,'object A deleted')
386 nt.assert_equals(out,'object A deleted')
310
387
311
388
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
389
390 If a doctest contains input whose output you don't want to verify identically
391 via doctest (random output, an object id, etc), you can mark a docstring with
392 ``#random``. All of these test will have their code executed but no output
393 checking will be done::
394
395 >>> 1+3
396 junk goes here... # random
397
398 >>> 1+2
399 again, anything goes #random
400 if multiline, the random mark is only needed once.
401
402 >>> 1+2
403 You can also put the random marker at the end:
404 # random
405
406 >>> 1+2
407 # random
408 .. or at the beginning.
409
410 In a case where you want an *entire* docstring to be executed but not verified
411 (this only serves to check that the code runs without crashing, so it should be
412 used very sparingly), you can put ``# all-random`` in the docstring.
413
319 .. _devel_config:
414 .. _devel_config:
320
415
321 Release checklist
416 Release checklist
@@ -340,6 +435,7 b' Most of the release process is automated by the :file:`release` script in the'
340
435
341 Porting to 3.0
436 Porting to 3.0
342 ==============
437 ==============
438
343 There are no definite plans for porting of IPython to python 3. The major
439 There are no definite plans for porting of IPython to python 3. The major
344 issue is the dependency on twisted framework for the networking/threading
440 issue is the dependency on twisted framework for the networking/threading
345 stuff. It is possible that it the traditional IPython interactive console
441 stuff. It is possible that it the traditional IPython interactive console
General Comments 0
You need to be logged in to leave comments. Login now