Show More
@@ -1,103 +1,244 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """IPython Test Suite Runner. |
|
2 | """IPython Test Suite Runner. | |
3 |
|
3 | |||
4 |
This module provides a main entry point to a user script to test IPython |
|
4 | This module provides a main entry point to a user script to test IPython | |
5 | from the command line. The main() routine can be used in a similar manner to |
|
5 | itself from the command line. There are two ways of running this script: | |
6 | the ``nosetests`` script, and it takes similar arguments, but if no arguments |
|
6 | ||
7 | are given it defaults to testing all of IPython. This should be preferred to |
|
7 | 1. With the syntax `iptest all`. This runs our entire test suite by | |
8 | using plain ``nosetests`` because a number of nose plugins necessary to test |
|
8 | calling this script (with different arguments) or trial recursively. This | |
9 | IPython correctly are automatically configured by this code. |
|
9 | causes modules and package to be tested in different processes, using nose | |
|
10 | or trial where appropriate. | |||
|
11 | 2. With the regular nose syntax, like `iptest -vvs IPython`. In this form | |||
|
12 | the script simply calls nose, but with special command line flags and | |||
|
13 | plugins loaded. | |||
|
14 | ||||
|
15 | For now, this script requires that both nose and twisted are installed. This | |||
|
16 | will change in the future. | |||
10 | """ |
|
17 | """ | |
11 |
|
18 | |||
12 | #----------------------------------------------------------------------------- |
|
19 | #----------------------------------------------------------------------------- | |
13 | # Module imports |
|
20 | # Module imports | |
14 | #----------------------------------------------------------------------------- |
|
21 | #----------------------------------------------------------------------------- | |
15 |
|
22 | |||
16 | # stdlib |
|
23 | import os | |
|
24 | import os.path as path | |||
17 | import sys |
|
25 | import sys | |
|
26 | import subprocess | |||
|
27 | import time | |||
18 | import warnings |
|
28 | import warnings | |
19 |
|
29 | |||
20 | # third-party |
|
|||
21 | import nose.plugins.builtin |
|
30 | import nose.plugins.builtin | |
22 | from nose.core import TestProgram |
|
31 | from nose.core import TestProgram | |
23 |
|
32 | |||
24 | # Our own imports |
|
|||
25 | from IPython.testing.plugin.ipdoctest import IPythonDoctest |
|
33 | from IPython.testing.plugin.ipdoctest import IPythonDoctest | |
26 |
|
34 | |||
27 | #----------------------------------------------------------------------------- |
|
35 | #----------------------------------------------------------------------------- | |
28 | # Constants and globals |
|
36 | # Globals and constants | |
29 | #----------------------------------------------------------------------------- |
|
37 | #----------------------------------------------------------------------------- | |
30 |
|
38 | |||
31 | # For the IPythonDoctest plugin, we need to exclude certain patterns that cause |
|
39 | # For the IPythonDoctest plugin, we need to exclude certain patterns that cause | |
32 | # testing problems. We should strive to minimize the number of skipped |
|
40 | # testing problems. We should strive to minimize the number of skipped | |
33 | # modules, since this means untested code. As the testing machinery |
|
41 | # modules, since this means untested code. As the testing machinery | |
34 | # solidifies, this list should eventually become empty. |
|
42 | # solidifies, this list should eventually become empty. | |
35 | EXCLUDE = ['IPython/external/', |
|
43 | EXCLUDE = ['IPython/external/', | |
36 | 'IPython/platutils_win32', |
|
44 | 'IPython/platutils_win32', | |
37 | 'IPython/frontend/cocoa', |
|
45 | 'IPython/frontend/cocoa', | |
38 | 'IPython/frontend/process/winprocess.py', |
|
46 | 'IPython/frontend/process/winprocess.py', | |
39 | 'IPython_doctest_plugin', |
|
47 | 'IPython_doctest_plugin', | |
40 | 'IPython/Gnuplot', |
|
48 | 'IPython/Gnuplot', | |
41 | 'IPython/Extensions/ipy_', |
|
49 | 'IPython/Extensions/ipy_', | |
42 | 'IPython/Extensions/clearcmd', |
|
50 | 'IPython/Extensions/clearcmd', | |
43 | 'IPython/Extensions/PhysicalQIn', |
|
51 | 'IPython/Extensions/PhysicalQIn', | |
44 | 'IPython/Extensions/scitedirector', |
|
52 | 'IPython/Extensions/scitedirector', | |
45 | 'IPython/Extensions/numeric_formats', |
|
53 | 'IPython/Extensions/numeric_formats', | |
46 | 'IPython/testing/attic', |
|
54 | 'IPython/testing/attic', | |
47 | ] |
|
55 | ] | |
48 |
|
56 | |||
49 | #----------------------------------------------------------------------------- |
|
57 | #----------------------------------------------------------------------------- | |
50 | # Functions and classes |
|
58 | # Functions and classes | |
51 | #----------------------------------------------------------------------------- |
|
59 | #----------------------------------------------------------------------------- | |
52 |
|
60 | |||
53 | def main(): |
|
61 | def run_iptest(): | |
54 | """Run the IPython test suite. |
|
62 | """Run the IPython test suite using nose. | |
|
63 | ||||
|
64 | This function is called when this script is **not** called with the form | |||
|
65 | `iptest all`. It simply calls nose with appropriate command line flags | |||
|
66 | and accepts all of the standard nose arguments. | |||
55 | """ |
|
67 | """ | |
56 |
|
68 | |||
57 | warnings.filterwarnings('ignore', |
|
69 | warnings.filterwarnings('ignore', | |
58 | 'This will be removed soon. Use IPython.testing.util instead') |
|
70 | 'This will be removed soon. Use IPython.testing.util instead') | |
59 |
|
71 | |||
60 | argv = sys.argv + [ |
|
72 | argv = sys.argv + [ | |
61 | # Loading ipdoctest causes problems with Twisted. |
|
73 | # Loading ipdoctest causes problems with Twisted. | |
62 | # I am removing this as a temporary fix to get the |
|
74 | # I am removing this as a temporary fix to get the | |
63 | # test suite back into working shape. Our nose |
|
75 | # test suite back into working shape. Our nose | |
64 | # plugin needs to be gone through with a fine |
|
76 | # plugin needs to be gone through with a fine | |
65 | # toothed comb to find what is causing the problem. |
|
77 | # toothed comb to find what is causing the problem. | |
66 | '--with-ipdoctest', |
|
78 | '--with-ipdoctest', | |
67 | '--ipdoctest-tests','--ipdoctest-extension=txt', |
|
79 | '--ipdoctest-tests','--ipdoctest-extension=txt', | |
68 | '--detailed-errors', |
|
80 | '--detailed-errors', | |
69 |
|
81 | |||
70 | # We add --exe because of setuptools' imbecility (it |
|
82 | # We add --exe because of setuptools' imbecility (it | |
71 | # blindly does chmod +x on ALL files). Nose does the |
|
83 | # blindly does chmod +x on ALL files). Nose does the | |
72 | # right thing and it tries to avoid executables, |
|
84 | # right thing and it tries to avoid executables, | |
73 | # setuptools unfortunately forces our hand here. This |
|
85 | # setuptools unfortunately forces our hand here. This | |
74 | # has been discussed on the distutils list and the |
|
86 | # has been discussed on the distutils list and the | |
75 | # setuptools devs refuse to fix this problem! |
|
87 | # setuptools devs refuse to fix this problem! | |
76 | '--exe', |
|
88 | '--exe', | |
77 | ] |
|
89 | ] | |
78 |
|
90 | |||
79 | # Detect if any tests were required by explicitly calling an IPython |
|
91 | # Detect if any tests were required by explicitly calling an IPython | |
80 | # submodule or giving a specific path |
|
92 | # submodule or giving a specific path | |
81 | has_tests = False |
|
93 | has_tests = False | |
82 | for arg in sys.argv: |
|
94 | for arg in sys.argv: | |
83 | if 'IPython' in arg or arg.endswith('.py') or \ |
|
95 | if 'IPython' in arg or arg.endswith('.py') or \ | |
84 | (':' in arg and '.py' in arg): |
|
96 | (':' in arg and '.py' in arg): | |
85 | has_tests = True |
|
97 | has_tests = True | |
86 | break |
|
98 | break | |
87 |
|
99 | |||
88 | # If nothing was specifically requested, test full IPython |
|
100 | # If nothing was specifically requested, test full IPython | |
89 | if not has_tests: |
|
101 | if not has_tests: | |
90 | argv.append('IPython') |
|
102 | argv.append('IPython') | |
91 |
|
103 | |||
92 | # Construct list of plugins, omitting the existing doctest plugin, which |
|
104 | # Construct list of plugins, omitting the existing doctest plugin, which | |
93 | # ours replaces (and extends). |
|
105 | # ours replaces (and extends). | |
94 | plugins = [IPythonDoctest(EXCLUDE)] |
|
106 | plugins = [IPythonDoctest(EXCLUDE)] | |
95 | for p in nose.plugins.builtin.plugins: |
|
107 | for p in nose.plugins.builtin.plugins: | |
96 | plug = p() |
|
108 | plug = p() | |
97 | if plug.name == 'doctest': |
|
109 | if plug.name == 'doctest': | |
98 | continue |
|
110 | continue | |
99 |
|
111 | |||
100 | #print '*** adding plugin:',plug.name # dbg |
|
112 | #print '*** adding plugin:',plug.name # dbg | |
101 | plugins.append(plug) |
|
113 | plugins.append(plug) | |
102 |
|
114 | |||
103 | TestProgram(argv=argv,plugins=plugins) |
|
115 | TestProgram(argv=argv,plugins=plugins) | |
|
116 | ||||
|
117 | ||||
|
118 | class IPTester(object): | |||
|
119 | """Call that calls iptest or trial in a subprocess. | |||
|
120 | """ | |||
|
121 | def __init__(self,runner='iptest',params=None): | |||
|
122 | """ """ | |||
|
123 | if runner == 'iptest': | |||
|
124 | self.runner = ['iptest','-v'] | |||
|
125 | else: | |||
|
126 | self.runner = ['trial'] | |||
|
127 | if params is None: | |||
|
128 | params = [] | |||
|
129 | if isinstance(params,str): | |||
|
130 | params = [params] | |||
|
131 | self.params = params | |||
|
132 | ||||
|
133 | # Assemble call | |||
|
134 | self.call_args = self.runner+self.params | |||
|
135 | ||||
|
136 | def run(self): | |||
|
137 | """Run the stored commands""" | |||
|
138 | return subprocess.call(self.call_args) | |||
|
139 | ||||
|
140 | ||||
|
141 | def make_runners(): | |||
|
142 | """Define the modules and packages that need to be tested. | |||
|
143 | """ | |||
|
144 | ||||
|
145 | # This omits additional top-level modules that should not be doctested. | |||
|
146 | # XXX: Shell.py is also ommited because of a bug in the skip_doctest | |||
|
147 | # decorator. See ticket https://bugs.launchpad.net/bugs/366209 | |||
|
148 | top_mod = \ | |||
|
149 | ['background_jobs.py', 'ColorANSI.py', 'completer.py', 'ConfigLoader.py', | |||
|
150 | 'CrashHandler.py', 'Debugger.py', 'deep_reload.py', 'demo.py', | |||
|
151 | 'DPyGetOpt.py', 'dtutils.py', 'excolors.py', 'FakeModule.py', | |||
|
152 | 'generics.py', 'genutils.py', 'history.py', 'hooks.py', 'ipapi.py', | |||
|
153 | 'iplib.py', 'ipmaker.py', 'ipstruct.py', 'irunner.py', 'Itpl.py', | |||
|
154 | 'Logger.py', 'macro.py', 'Magic.py', 'OInspect.py', | |||
|
155 | 'OutputTrap.py', 'platutils.py', 'prefilter.py', 'Prompts.py', | |||
|
156 | 'PyColorize.py', 'Release.py', 'rlineimpl.py', 'shadowns.py', | |||
|
157 | 'shellglobals.py', 'strdispatch.py', 'twshell.py', | |||
|
158 | 'ultraTB.py', 'upgrade_dir.py', 'usage.py', 'wildcard.py', | |||
|
159 | # See note above for why this is skipped | |||
|
160 | # 'Shell.py', | |||
|
161 | 'winconsole.py'] | |||
|
162 | ||||
|
163 | if os.name == 'posix': | |||
|
164 | top_mod.append('platutils_posix.py') | |||
|
165 | elif sys.platform == 'win32': | |||
|
166 | top_mod.append('platutils_win32.py') | |||
|
167 | else: | |||
|
168 | top_mod.append('platutils_dummy.py') | |||
|
169 | ||||
|
170 | top_pack = ['config','Extensions','frontend','gui','kernel', | |||
|
171 | 'testing','tests','tools','UserConfig'] | |||
|
172 | ||||
|
173 | modules = ['IPython.%s' % m[:-3] for m in top_mod ] | |||
|
174 | packages = ['IPython.%s' % m for m in top_pack ] | |||
|
175 | ||||
|
176 | # Make runners | |||
|
177 | runners = dict(zip(top_pack, [IPTester(params=v) for v in packages])) | |||
|
178 | ||||
|
179 | try: | |||
|
180 | import zope.interface | |||
|
181 | import twisted | |||
|
182 | import foolscap | |||
|
183 | except ImportError: | |||
|
184 | pass | |||
|
185 | else: | |||
|
186 | runners['trial'] = IPTester('trial',['IPython']) | |||
|
187 | ||||
|
188 | for m in modules: | |||
|
189 | runners[m] = IPTester(params=m) | |||
|
190 | ||||
|
191 | return runners | |||
|
192 | ||||
|
193 | ||||
|
194 | def run_iptestall(): | |||
|
195 | """Run the entire IPython test suite by calling nose and trial. | |||
|
196 | ||||
|
197 | This function constructs :class:`IPTester` instances for all IPython | |||
|
198 | modules and package and then runs each of them. This causes the modules | |||
|
199 | and packages of IPython to be tested each in their own subprocess using | |||
|
200 | nose or twisted.trial appropriately. | |||
|
201 | """ | |||
|
202 | runners = make_runners() | |||
|
203 | # Run all test runners, tracking execution time | |||
|
204 | failed = {} | |||
|
205 | t_start = time.time() | |||
|
206 | for name,runner in runners.iteritems(): | |||
|
207 | print '*'*77 | |||
|
208 | print 'IPython test set:',name | |||
|
209 | res = runner.run() | |||
|
210 | if res: | |||
|
211 | failed[name] = res | |||
|
212 | t_end = time.time() | |||
|
213 | t_tests = t_end - t_start | |||
|
214 | nrunners = len(runners) | |||
|
215 | nfail = len(failed) | |||
|
216 | # summarize results | |||
|
217 | ||||
|
218 | print '*'*77 | |||
|
219 | print 'Ran %s test sets in %.3fs' % (nrunners, t_tests) | |||
|
220 | ||||
|
221 | if not failed: | |||
|
222 | print 'OK' | |||
|
223 | else: | |||
|
224 | # If anything went wrong, point out what command to rerun manually to | |||
|
225 | # see the actual errors and individual summary | |||
|
226 | print 'ERROR - %s out of %s test sets failed.' % (nfail, nrunners) | |||
|
227 | for name in failed: | |||
|
228 | failed_runner = runners[name] | |||
|
229 | print '-'*40 | |||
|
230 | print 'Runner failed:',name | |||
|
231 | print 'You may wish to rerun this one individually, with:' | |||
|
232 | print ' '.join(failed_runner.call_args) | |||
|
233 | ||||
|
234 | ||||
|
235 | ||||
|
236 | def main(): | |||
|
237 | if sys.argv[1] == 'all': | |||
|
238 | run_iptestall() | |||
|
239 | else: | |||
|
240 | run_iptest() | |||
|
241 | ||||
|
242 | ||||
|
243 | if __name__ == '__main__': | |||
|
244 | main() No newline at end of file |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now