##// END OF EJS Templates
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
Fernando Perez -
Show More
@@ -16,8 +16,6 b' For now, this script requires that both nose and twisted are installed. This'
16 will change in the future.
16 will change in the future.
17 """
17 """
18
18
19 from __future__ import absolute_import
20
21 #-----------------------------------------------------------------------------
19 #-----------------------------------------------------------------------------
22 # Module imports
20 # Module imports
23 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
@@ -36,7 +34,7 b' import warnings'
36 # We need to monkeypatch a small problem in nose itself first, before importing
34 # We need to monkeypatch a small problem in nose itself first, before importing
37 # it for actual use. This should get into nose upstream, but its release cycle
35 # it for actual use. This should get into nose upstream, but its release cycle
38 # is slow and we need it for our parametric tests to work correctly.
36 # is slow and we need it for our parametric tests to work correctly.
39 from . import nosepatch
37 from IPython.testing import nosepatch
40 # Now, proceed to import nose itself
38 # Now, proceed to import nose itself
41 import nose.plugins.builtin
39 import nose.plugins.builtin
42 from nose.core import TestProgram
40 from nose.core import TestProgram
@@ -44,9 +42,9 b' from nose.core import TestProgram'
44 # Our own imports
42 # Our own imports
45 from IPython.utils import genutils
43 from IPython.utils import genutils
46 from IPython.utils.platutils import find_cmd, FindCmdError
44 from IPython.utils.platutils import find_cmd, FindCmdError
47 from . import globalipapp
45 from IPython.testing import globalipapp
48 from . import tools
46 from IPython.testing import tools
49 from .plugin.ipdoctest import IPythonDoctest
47 from IPython.testing.plugin.ipdoctest import IPythonDoctest
50
48
51 pjoin = path.join
49 pjoin = path.join
52
50
@@ -189,24 +187,18 b' class IPTester(object):'
189 #: list, process ids of subprocesses we start (for cleanup)
187 #: list, process ids of subprocesses we start (for cleanup)
190 pids = None
188 pids = None
191
189
192 def __init__(self,runner='iptest',params=None):
190 def __init__(self, runner='iptest', params=None):
193 """Create new test runner."""
191 """Create new test runner."""
194 if runner == 'iptest':
192 if runner == 'iptest':
195 # Find our own 'iptest' script OS-level entry point
193 # Find our own 'iptest' script OS-level entry point. Don't look
196 try:
194 # system-wide, so we are sure we pick up *this one*. And pass
197 iptest_path = os.path.abspath(find_cmd('iptest'))
195 # through to subprocess call our own sys.argv
198 except FindCmdError:
196 self.runner = tools.cmd2argv(__file__) + sys.argv[1:]
199 # Script not installed (may be the case for testing situations
200 # that are running from a source tree only), pull from internal
201 # path:
202 pak_dir = os.path.abspath(genutils.get_ipython_package_dir())
203 iptest_path = pjoin(pak_dir, 'scripts', 'iptest')
204 self.runner = tools.cmd2argv(iptest_path) + ['-v']
205 else:
197 else:
206 self.runner = tools.cmd2argv(os.path.abspath(find_cmd('trial')))
198 self.runner = tools.cmd2argv(os.path.abspath(find_cmd('trial')))
207 if params is None:
199 if params is None:
208 params = []
200 params = []
209 if isinstance(params,str):
201 if isinstance(params, str):
210 params = [params]
202 params = [params]
211 self.params = params
203 self.params = params
212
204
@@ -272,12 +264,13 b' def make_runners():'
272 # is twisted-based, because nose picks up doctests that
264 # is twisted-based, because nose picks up doctests that
273 # twisted doesn't.
265 # twisted doesn't.
274 'kernel']
266 'kernel']
267 # The machinery in kernel needs twisted for real testing
275 trial_packages = ['kernel']
268 trial_packages = ['kernel']
276
269
277 if have_wx:
270 if have_wx:
278 nose_packages.append('gui')
271 nose_packages.append('gui')
279
272
280 #nose_packages = ['core'] # dbg
273 #nose_packages = ['config', 'utils'] # dbg
281 #trial_packages = [] # dbg
274 #trial_packages = [] # dbg
282
275
283 nose_packages = ['IPython.%s' % m for m in nose_packages ]
276 nose_packages = ['IPython.%s' % m for m in nose_packages ]
@@ -285,11 +278,12 b' def make_runners():'
285
278
286 # Make runners, most with nose
279 # Make runners, most with nose
287 nose_testers = [IPTester(params=v) for v in nose_packages]
280 nose_testers = [IPTester(params=v) for v in nose_packages]
288 runners = dict(zip(nose_packages, nose_testers))
281 runners = zip(nose_packages, nose_testers)
282
289 # And add twisted ones if conditions are met
283 # And add twisted ones if conditions are met
290 if have_zi and have_twisted and have_foolscap:
284 if have_zi and have_twisted and have_foolscap:
291 trial_testers = [IPTester('trial',params=v) for v in trial_packages]
285 trial_testers = [IPTester('trial', params=v) for v in trial_packages]
292 runners.update(dict(zip(trial_packages,trial_testers)))
286 runners.extend(zip(trial_packages, trial_testers))
293
287
294 return runners
288 return runners
295
289
@@ -312,8 +306,6 b' def run_iptest():'
312 '--with-ipdoctest',
306 '--with-ipdoctest',
313 '--ipdoctest-tests','--ipdoctest-extension=txt',
307 '--ipdoctest-tests','--ipdoctest-extension=txt',
314
308
315 #'-x','-s', # dbg
316
317 # We add --exe because of setuptools' imbecility (it
309 # We add --exe because of setuptools' imbecility (it
318 # blindly does chmod +x on ALL files). Nose does the
310 # blindly does chmod +x on ALL files). Nose does the
319 # right thing and it tries to avoid executables,
311 # right thing and it tries to avoid executables,
@@ -323,21 +315,9 b' def run_iptest():'
323 '--exe',
315 '--exe',
324 ]
316 ]
325
317
326 # Detect if any tests were required by explicitly calling an IPython
327 # submodule or giving a specific path
328 has_tests = False
329 for arg in sys.argv:
330 if 'IPython' in arg or arg.endswith('.py') or \
331 (':' in arg and '.py' in arg):
332 has_tests = True
333 break
334
335 # If nothing was specifically requested, test full IPython
336 if not has_tests:
337 argv.append('IPython')
338
318
339 ## # Construct list of plugins, omitting the existing doctest plugin, which
319 # Construct list of plugins, omitting the existing doctest plugin, which
340 ## # ours replaces (and extends).
320 # ours replaces (and extends).
341 plugins = [IPythonDoctest(make_exclude())]
321 plugins = [IPythonDoctest(make_exclude())]
342 for p in nose.plugins.builtin.plugins:
322 for p in nose.plugins.builtin.plugins:
343 plug = p()
323 plug = p()
@@ -348,7 +328,7 b' def run_iptest():'
348 # We need a global ipython running in this process
328 # We need a global ipython running in this process
349 globalipapp.start_ipython()
329 globalipapp.start_ipython()
350 # Now nose can run
330 # Now nose can run
351 TestProgram(argv=argv,plugins=plugins)
331 TestProgram(argv=argv, plugins=plugins)
352
332
353
333
354 def run_iptestall():
334 def run_iptestall():
@@ -371,15 +351,15 b' def run_iptestall():'
371 os.chdir(testdir)
351 os.chdir(testdir)
372
352
373 # Run all test runners, tracking execution time
353 # Run all test runners, tracking execution time
374 failed = {}
354 failed = []
375 t_start = time.time()
355 t_start = time.time()
376 try:
356 try:
377 for name,runner in runners.iteritems():
357 for (name, runner) in runners:
378 print '*'*77
358 print '*'*70
379 print 'IPython test group:',name
359 print 'IPython test group:',name
380 res = runner.run()
360 res = runner.run()
381 if res:
361 if res:
382 failed[name] = res
362 failed.append( (name, runner) )
383 finally:
363 finally:
384 os.chdir(curdir)
364 os.chdir(curdir)
385 t_end = time.time()
365 t_end = time.time()
@@ -388,7 +368,7 b' def run_iptestall():'
388 nfail = len(failed)
368 nfail = len(failed)
389 # summarize results
369 # summarize results
390 print
370 print
391 print '*'*77
371 print '*'*70
392 print 'Ran %s test groups in %.3fs' % (nrunners, t_tests)
372 print 'Ran %s test groups in %.3fs' % (nrunners, t_tests)
393 print
373 print
394 if not failed:
374 if not failed:
@@ -397,8 +377,7 b' def run_iptestall():'
397 # If anything went wrong, point out what command to rerun manually to
377 # If anything went wrong, point out what command to rerun manually to
398 # see the actual errors and individual summary
378 # see the actual errors and individual summary
399 print 'ERROR - %s out of %s test groups failed.' % (nfail, nrunners)
379 print 'ERROR - %s out of %s test groups failed.' % (nfail, nrunners)
400 for name in failed:
380 for name, failed_runner in failed:
401 failed_runner = runners[name]
402 print '-'*40
381 print '-'*40
403 print 'Runner failed:',name
382 print 'Runner failed:',name
404 print 'You may wish to rerun this one individually, with:'
383 print 'You may wish to rerun this one individually, with:'
@@ -407,13 +386,11 b' def run_iptestall():'
407
386
408
387
409 def main():
388 def main():
410 if len(sys.argv) == 1:
389 for arg in sys.argv[1:]:
411 run_iptestall()
390 if arg.startswith('IPython'):
412 else:
413 if sys.argv[1] == 'all':
414 run_iptestall()
415 else:
416 run_iptest()
391 run_iptest()
392 else:
393 run_iptestall()
417
394
418
395
419 if __name__ == '__main__':
396 if __name__ == '__main__':
@@ -1,4 +1,3 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
1 # encoding: utf-8
3
2
4 def test_import_coloransi():
3 def test_import_coloransi():
General Comments 0
You need to be logged in to leave comments. Login now