##// END OF EJS Templates
Doc updates to testing to reflect recent changes....
Fernando Perez -
Show More
@@ -1,121 +1,121 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Release data for the IPython project."""
3 3
4 4 #*****************************************************************************
5 5 # Copyright (C) 2008-2009 The IPython Development Team
6 6 # Copyright (C) 2001-2008 Fernando Perez <fperez@colorado.edu>
7 7 # Copyright (c) 2001 Janko Hauser <jhauser@zscout.de> and Nathaniel Gray
8 8 # <n8gray@caltech.edu>
9 9 #
10 10 # Distributed under the terms of the BSD License. The full license is in
11 11 # the file COPYING, distributed as part of this software.
12 12 #*****************************************************************************
13 13
14 14 # Name of the package for release purposes. This is the name which labels
15 15 # the tarballs and RPMs made by distutils, so it's best to lowercase it.
16 16 name = 'ipython'
17 17
18 18 # For versions with substrings (like 0.6.16.svn), use an extra . to separate
19 19 # the new substring. We have to avoid using either dashes or underscores,
20 20 # because bdist_rpm does not accept dashes (an RPM) convention, and
21 21 # bdist_deb does not accept underscores (a Debian convention).
22 22
23 23 development = True # change this to False to do a release
24 24 version_base = '0.11'
25 25 branch = 'ipython'
26 revision = '1321'
26 revision = '1340'
27 27
28 28 if development:
29 29 if branch == 'ipython':
30 30 version = '%s.bzr.r%s' % (version_base, revision)
31 31 else:
32 32 version = '%s.bzr.r%s.%s' % (version_base, revision, branch)
33 33 else:
34 34 version = version_base
35 35
36 36
37 37 description = "An interactive computing environment for Python"
38 38
39 39 long_description = \
40 40 """
41 41 The goal of IPython is to create a comprehensive environment for
42 42 interactive and exploratory computing. To support this goal, IPython
43 43 has two main components:
44 44
45 45 * An enhanced interactive Python shell.
46 46
47 47 * An architecture for interactive parallel computing.
48 48
49 49 The enhanced interactive Python shell has the following main features:
50 50
51 51 * Comprehensive object introspection.
52 52
53 53 * Input history, persistent across sessions.
54 54
55 55 * Caching of output results during a session with automatically generated
56 56 references.
57 57
58 58 * Readline based name completion.
59 59
60 60 * Extensible system of 'magic' commands for controlling the environment and
61 61 performing many tasks related either to IPython or the operating system.
62 62
63 63 * Configuration system with easy switching between different setups (simpler
64 64 than changing $PYTHONSTARTUP environment variables every time).
65 65
66 66 * Session logging and reloading.
67 67
68 68 * Extensible syntax processing for special purpose situations.
69 69
70 70 * Access to the system shell with user-extensible alias system.
71 71
72 72 * Easily embeddable in other Python programs and wxPython GUIs.
73 73
74 74 * Integrated access to the pdb debugger and the Python profiler.
75 75
76 76 The parallel computing architecture has the following main features:
77 77
78 78 * Quickly parallelize Python code from an interactive Python/IPython session.
79 79
80 80 * A flexible and dynamic process model that be deployed on anything from
81 81 multicore workstations to supercomputers.
82 82
83 83 * An architecture that supports many different styles of parallelism, from
84 84 message passing to task farming.
85 85
86 86 * Both blocking and fully asynchronous interfaces.
87 87
88 88 * High level APIs that enable many things to be parallelized in a few lines
89 89 of code.
90 90
91 91 * Share live parallel jobs with other users securely.
92 92
93 93 * Dynamically load balanced task farming system.
94 94
95 95 * Robust error handling in parallel code.
96 96
97 97 The latest development version is always available from IPython's `Launchpad
98 98 site <http://launchpad.net/ipython>`_.
99 99 """
100 100
101 101 license = 'BSD'
102 102
103 103 authors = {'Fernando' : ('Fernando Perez','fperez.net@gmail.com'),
104 104 'Janko' : ('Janko Hauser','jhauser@zscout.de'),
105 105 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu'),
106 106 'Ville' : ('Ville Vainio','vivainio@gmail.com'),
107 107 'Brian' : ('Brian E Granger', 'ellisonbg@gmail.com'),
108 108 'Min' : ('Min Ragan-Kelley', 'benjaminrk@gmail.com')
109 109 }
110 110
111 111 author = 'The IPython Development Team'
112 112
113 113 author_email = 'ipython-dev@scipy.org'
114 114
115 115 url = 'http://ipython.scipy.org'
116 116
117 117 download_url = 'http://ipython.scipy.org/dist'
118 118
119 119 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
120 120
121 121 keywords = ['Interactive','Interpreter','Shell','Parallel','Distributed']
@@ -1,372 +1,372 b''
1 1 .. _testing:
2 2
3 3 ==========================================
4 4 Testing IPython for users and developers
5 5 ==========================================
6 6
7 7 Overview
8 8 ========
9 9
10 10 It is extremely important that all code contributed to IPython has tests.
11 11 Tests should be written as unittests, doctests or other entities that the
12 12 IPython test system can detect. See below for more details on this.
13 13
14 14 Each subpackage in IPython should have its own :file:`tests` directory that
15 15 contains all of the tests for that subpackage. All of the files in the
16 16 :file:`tests` directory should have the word "tests" in them to enable
17 17 the testing framework to find them.
18 18
19 19 In docstrings, examples (either using IPython prompts like ``In [1]:`` or
20 20 'classic' python ``>>>`` ones) can and should be included. The testing system
21 21 will detect them as doctests and will run them; it offers control to skip parts
22 22 or all of a specific doctest if the example is meant to be informative but
23 23 shows non-reproducible information (like filesystem data).
24 24
25 25 If a subpackage has any dependencies beyond the Python standard library, the
26 26 tests for that subpackage should be skipped if the dependencies are not found.
27 27 This is very important so users don't get tests failing simply because they
28 28 don't have dependencies.
29 29
30 30 The testing system we use is a hybrid of nose_ and Twisted's trial_ test runner.
31 31 We use both because nose detects more things than Twisted and allows for more
32 32 flexible (and lighter-weight) ways of writing tests; in particular we've
33 33 developed a nose plugin that allows us to paste verbatim IPython sessions and
34 34 test them as doctests, which is extremely important for us. But the parts of
35 35 IPython that depend on Twisted must be tested using trial, because only trial
36 36 manages the Twisted reactor correctly.
37 37
38 38 .. _nose: http://code.google.com/p/python-nose
39 39 .. _trial: http://twistedmatrix.com/trac/wiki/TwistedTrial
40 40
41 41
42 42 For the impatient: running the tests
43 43 ====================================
44 44
45 45 You can run IPython from the source download directory without even installing
46 46 it system-wide or having configure anything, by typing at the terminal:
47 47
48 48 .. code-block:: bash
49 49
50 50 python ipython.py
51 51
52 52 and similarly, you can execute the built-in test suite with:
53 53
54 54 .. code-block:: bash
55 55
56 56 python iptest.py
57 57
58 58
59 This script manages intelligently both nose and trial, choosing the correct
60 test system for each of IPython's components.
61
59 62 Once you have either installed it or at least configured your system to be
60 63 able to import IPython, you can run the tests with:
61 64
62 65 .. code-block:: bash
63 66
64 67 python -c "import IPython; IPython.test()"
65 68
66 69 This should work as long as IPython can be imported, even if you haven't fully
67 70 installed the user-facing scripts yet (common in a development environment).
71 Once you have installed IPython, you will have available system-wide a script
72 called :file:`iptest` that does the exact same as the :file:`iptest.py` script
73 in the source directory, so you can then test simply with:
74
75 .. code-block:: bash
76
77 iptest [args]
68 78
69 79
70 80 Regardless of how you run things, you should eventually see something like:
71 81
72 82 .. code-block:: bash
73 83
74 ************************************************************************
75 Ran 10 test groups in 35.228s
84 **********************************************************************
85 Ran 11 test groups in 64.117s
76 86
77 87 OK
78 88
79 If not, there will be a message indicating which test group failed and how to
80 rerun that group individually.
81
82 But IPython ships with an entry point script called :file:`iptest` that offers
83 fine-grain control over the test process and is particularly useful for
84 developers; this script also manages intelligently both nose and trial,
85 choosing the correct test system for each of IPython's components. Running
86 :file:`iptest` without arguments gives output identical to that above, but with
87 it, you can also run specific tests with fine control. The :file:`iptest`
88 script is installed with IPython, but if you are running from a source tree,
89 you can find it in the :file:`IPython/scripts` directory and you can run
90 directly from there.
91 89
92 For example, this tests the :mod:`IPython.utils` subpackage, the :option:`-v`
93 option shows progress indicators:
90 If not, there will be a message indicating which test group failed and how to
91 rerun that group individually. For example, this tests the
92 :mod:`IPython.utils` subpackage, the :option:`-v` option shows progress
93 indicators:
94 94
95 95 .. code-block:: bash
96 96
97 maqroll[ipython]> cd IPython/scripts/
98 maqroll[scripts]> ./iptest -v IPython.utils
99 ..........................SS..SSS............................S.S.........
100 ...................................................
97 $ python iptest.py -v IPython.utils
98 ..........................SS..SSS............................S.S...
99 .........................................................
101 100 ----------------------------------------------------------------------
102 Ran 125 tests in 0.070s
101 Ran 125 tests in 0.119s
103 102
104 103 OK (SKIP=7)
105 104
106 Because :file:`iptest` is based on nose, you can use all nose options and
107 syntax, typing ``iptest -h`` shows all available options. For example, this
108 lets you run the specific test :func:`test_rehashx` inside the
105
106 Because the IPython test machinery is based on nose, you can use all nose
107 options and syntax, typing ``iptest -h`` shows all available options. For
108 example, this lets you run the specific test :func:`test_rehashx` inside the
109 109 :mod:`test_magic` module:
110 110
111 111 .. code-block:: bash
112 112
113 maqroll[scripts]> ./iptest -vv IPython.core.tests.test_magic:test_rehashx
113 $ python iptest.py -vv IPython.core.tests.test_magic:test_rehashx
114 114 IPython.core.tests.test_magic.test_rehashx(True,) ... ok
115 115 IPython.core.tests.test_magic.test_rehashx(True,) ... ok
116 116
117 117 ----------------------------------------------------------------------
118 Ran 2 tests in 0.101s
118 Ran 2 tests in 0.100s
119 119
120 120 OK
121 121
122 122 When developing, the :option:`--pdb` and :option:`--pdb-failures` of nose are
123 123 particularly useful, these drop you into an interactive pdb session at the
124 124 point of the error or failure respectively.
125 125
126 126 To run Twisted-using tests, use the :command:`trial` command on a per file or
127 127 package basis:
128 128
129 129 .. code-block:: bash
130 130
131 131 trial IPython.kernel
132 132
133 133
134 134 For developers: writing tests
135 135 =============================
136 136
137 137 By now IPython has a reasonable test suite, so the best way to see what's
138 138 available is to look at the :file:`tests` directory in most subpackages. But
139 139 here are a few pointers to make the process easier.
140 140
141 141
142 142 Main tools: :mod:`IPython.testing`
143 143 ----------------------------------
144 144
145 145 The :mod:`IPython.testing` package is where all of the machinery to test
146 146 IPython (rather than the tests for its various parts) lives. In particular,
147 147 the :mod:`iptest` module in there has all the smarts to control the test
148 148 process. In there, the :func:`make_exclude` function is used to build a
149 149 blacklist of exclusions, these are modules that do not get even imported for
150 150 tests. This is important so that things that would fail to even import because
151 151 of missing dependencies don't give errors to end users, as we stated above.
152 152
153 153 The :mod:`decorators` module contains a lot of useful decorators, especially
154 154 useful to mark individual tests that should be skipped under certain conditions
155 155 (rather than blacklisting the package altogether because of a missing major
156 156 dependency).
157 157
158 158 Our nose plugin for doctests
159 159 ----------------------------
160 160
161 161 The :mod:`plugin` subpackage in testing contains a nose plugin called
162 162 :mod:`ipdoctest` that teaches nose about IPython syntax, so you can write
163 163 doctests with IPython prompts. You can also mark doctest output with ``#
164 164 random`` for the output corresponding to a single input to be ignored (stronger
165 165 than using ellipsis and useful to keep it as an example). If you want the
166 166 entire docstring to be executed but none of the output from any input to be
167 167 checked, you can use the ``# all-random`` marker. The
168 168 :mod:`IPython.testing.plugin.dtexample` module contains examples of how to use
169 169 these; for reference here is how to use ``# random``::
170 170
171 171 def ranfunc():
172 172 """A function with some random output.
173 173
174 174 Normal examples are verified as usual:
175 175 >>> 1+3
176 176 4
177 177
178 178 But if you put '# random' in the output, it is ignored:
179 179 >>> 1+3
180 180 junk goes here... # random
181 181
182 182 >>> 1+2
183 183 again, anything goes #random
184 184 if multiline, the random mark is only needed once.
185 185
186 186 >>> 1+2
187 187 You can also put the random marker at the end:
188 188 # random
189 189
190 190 >>> 1+2
191 191 # random
192 192 .. or at the beginning.
193 193
194 194 More correct input is properly verified:
195 195 >>> ranfunc()
196 196 'ranfunc'
197 197 """
198 198 return 'ranfunc'
199 199
200 200 and an example of ``# all-random``::
201 201
202 202 def random_all():
203 203 """A function where we ignore the output of ALL examples.
204 204
205 205 Examples:
206 206
207 207 # all-random
208 208
209 209 This mark tells the testing machinery that all subsequent examples
210 210 should be treated as random (ignoring their output). They are still
211 211 executed, so if a they raise an error, it will be detected as such,
212 212 but their output is completely ignored.
213 213
214 214 >>> 1+3
215 215 junk goes here...
216 216
217 217 >>> 1+3
218 218 klasdfj;
219 219
220 220 In [8]: print 'hello'
221 221 world # random
222 222
223 223 In [9]: iprand()
224 224 Out[9]: 'iprand'
225 225 """
226 226 return 'iprand'
227 227
228 228
229 229 When writing docstrings, you can use the ``@skip_doctest`` decorator to
230 230 indicate that a docstring should *not* be treated as a doctest at all. The
231 231 difference betwee ``# all-random`` and ``@skip_doctest`` is that the former
232 232 executes the example but ignores output, while the latter doesn't execute any
233 233 code. ``@skip_doctest`` should be used for docstrings whose examples are
234 234 purely informational.
235 235
236 236 If a given docstring fails under certain conditions but otherwise is a good
237 237 doctest, you can use code like the following, that relies on the 'null'
238 238 decorator to leave the docstring intact where it works as a test::
239 239
240 240 # The docstring for full_path doctests differently on win32 (different path
241 241 # separator) so just skip the doctest there, and use a null decorator
242 242 # elsewhere:
243 243
244 244 doctest_deco = dec.skip_doctest if sys.platform == 'win32' else dec.null_deco
245 245
246 246 @doctest_deco
247 247 def full_path(startPath,files):
248 248 """Make full paths for all the listed files, based on startPath..."""
249 249
250 250 # function body follows...
251 251
252 252 With our nose plugin that understands IPython syntax, an extremely effective
253 253 way to write tests is to simply copy and paste an interactive session into a
254 254 docstring. You can writing this type of test, where your docstring is meant
255 255 *only* as a test, by prefixing the function name with ``doctest_`` and leaving
256 256 its body *absolutely empty* other than the docstring. In
257 257 :mod:`IPython.core.tests.test_magic` you can find several examples of this, but
258 258 for completeness sake, your code should look like this (a simple case)::
259 259
260 260 def doctest_time():
261 261 """
262 262 In [10]: %time None
263 263 CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s
264 264 Wall time: 0.00 s
265 265 """
266 266
267 267 This function is only analyzed for its docstring but it is not considered a
268 268 separate test, which is why its body should be empty.
269 269
270 270
271 271 Parametric tests done right
272 272 ---------------------------
273 273
274 274 If you need to run multiple tests inside the same standalone function or method
275 275 of a :class:`unittest.TestCase` subclass, IPython provides the ``parametric``
276 276 decorator for this purpose. This is superior to how test generators work in
277 277 nose, because IPython's keeps intact your stack, which makes debugging vastly
278 278 easier. For example, these are some parametric tests both in class form and as
279 279 a standalone function (choose in each situation the style that best fits the
280 280 problem at hand, since both work)::
281 281
282 282 from IPython.testing import decorators as dec
283 283
284 284 def is_smaller(i,j):
285 285 assert i<j,"%s !< %s" % (i,j)
286 286
287 287 class Tester(ParametricTestCase):
288 288
289 289 def test_parametric(self):
290 290 yield is_smaller(3, 4)
291 291 x, y = 1, 2
292 292 yield is_smaller(x, y)
293 293
294 294 @dec.parametric
295 295 def test_par_standalone():
296 296 yield is_smaller(3, 4)
297 297 x, y = 1, 2
298 298 yield is_smaller(x, y)
299 299
300 300
301 301 Writing tests for Twisted-using code
302 302 ------------------------------------
303 303
304 304 Tests of Twisted [Twisted]_ using code should be written by subclassing the
305 305 ``TestCase`` class that comes with ``twisted.trial.unittest``. Furthermore, all
306 306 :class:`Deferred` instances that are created in the test must be properly
307 307 chained and the final one *must* be the return value of the test method.
308 308
309 309 .. note::
310 310
311 311 The best place to see how to use the testing tools, are the tests for these
312 312 tools themselves, which live in :mod:`IPython.testing.tests`.
313 313
314 314
315 315 Design requirements
316 316 ===================
317 317
318 318 This section is a set of notes on the key points of the IPython testing needs,
319 319 that were used when writing the system and should be kept for reference as it
320 320 eveolves.
321 321
322 322 Testing IPython in full requires modifications to the default behavior of nose
323 323 and doctest, because the IPython prompt is not recognized to determine Python
324 324 input, and because IPython admits user input that is not valid Python (things
325 325 like ``%magics`` and ``!system commands``.
326 326
327 327 We basically need to be able to test the following types of code:
328 328
329 329 1. Pure Python files containing normal tests. These are not a problem, since
330 330 Nose will pick them up as long as they conform to the (flexible) conventions
331 331 used by nose to recognize tests.
332 332
333 333 2. Python files containing doctests. Here, we have two possibilities:
334 334 - The prompts are the usual ``>>>`` and the input is pure Python.
335 335 - The prompts are of the form ``In [1]:`` and the input can contain extended
336 336 IPython expressions.
337 337
338 338 In the first case, Nose will recognize the doctests as long as it is called
339 339 with the ``--with-doctest`` flag. But the second case will likely require
340 340 modifications or the writing of a new doctest plugin for Nose that is
341 341 IPython-aware.
342 342
343 343 3. ReStructuredText files that contain code blocks. For this type of file, we
344 344 have three distinct possibilities for the code blocks:
345 345 - They use ``>>>`` prompts.
346 346 - They use ``In [1]:`` prompts.
347 347 - They are standalone blocks of pure Python code without any prompts.
348 348
349 349 The first two cases are similar to the situation #2 above, except that in
350 350 this case the doctests must be extracted from input code blocks using
351 351 docutils instead of from the Python docstrings.
352 352
353 353 In the third case, we must have a convention for distinguishing code blocks
354 354 that are meant for execution from others that may be snippets of shell code
355 355 or other examples not meant to be run. One possibility is to assume that
356 356 all indented code blocks are meant for execution, but to have a special
357 357 docutils directive for input that should not be executed.
358 358
359 359 For those code blocks that we will execute, the convention used will simply
360 360 be that they get called and are considered successful if they run to
361 361 completion without raising errors. This is similar to what Nose does for
362 362 standalone test functions, and by putting asserts or other forms of
363 363 exception-raising statements it becomes possible to have literate examples
364 364 that double as lightweight tests.
365 365
366 366 4. Extension modules with doctests in function and method docstrings.
367 367 Currently Nose simply can't find these docstrings correctly, because the
368 368 underlying doctest DocTestFinder object fails there. Similarly to #2 above,
369 369 the docstrings could have either pure python or IPython prompts.
370 370
371 371 Of these, only 3-c (reST with standalone code blocks) is not implemented at
372 372 this point.
General Comments 0
You need to be logged in to leave comments. Login now