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