2008-08-24 14:37:40 +08:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""IPython Test Suite Runner.
|
2009-03-11 13:49:08 +08:00
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
This module provides a main entry point to a user script to test IPython
|
|
|
|
itself from the command line. There are two ways of running this script:
|
|
|
|
|
|
|
|
1. With the syntax `iptest all`. This runs our entire test suite by
|
|
|
|
calling this script (with different arguments) or trial recursively. This
|
|
|
|
causes modules and package to be tested in different processes, using nose
|
|
|
|
or trial where appropriate.
|
|
|
|
2. With the regular nose syntax, like `iptest -vvs IPython`. In this form
|
|
|
|
the script simply calls nose, but with special command line flags and
|
|
|
|
plugins loaded.
|
|
|
|
|
|
|
|
For now, this script requires that both nose and twisted are installed. This
|
|
|
|
will change in the future.
|
2008-08-24 14:37:40 +08:00
|
|
|
"""
|
|
|
|
|
2009-03-11 13:49:08 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Module imports
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
import os
|
|
|
|
import os.path as path
|
2008-08-24 14:37:40 +08:00
|
|
|
import sys
|
2009-04-25 01:12:50 +08:00
|
|
|
import subprocess
|
|
|
|
import time
|
2008-08-24 14:37:40 +08:00
|
|
|
import warnings
|
|
|
|
|
|
|
|
import nose.plugins.builtin
|
2009-03-11 13:49:08 +08:00
|
|
|
from nose.core import TestProgram
|
2008-08-24 14:37:40 +08:00
|
|
|
|
2009-04-26 01:05:09 +08:00
|
|
|
from IPython.platutils import find_cmd
|
2008-08-24 14:37:40 +08:00
|
|
|
from IPython.testing.plugin.ipdoctest import IPythonDoctest
|
|
|
|
|
2009-04-26 00:04:56 +08:00
|
|
|
pjoin = path.join
|
|
|
|
|
2009-03-11 13:49:08 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
2009-04-26 03:27:03 +08:00
|
|
|
# Logic for skipping doctests
|
2009-03-11 13:49:08 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2009-04-26 03:27:03 +08:00
|
|
|
def test_for(mod):
|
|
|
|
"""Test to see if mod is importable."""
|
|
|
|
try:
|
|
|
|
__import__(mod)
|
|
|
|
except ImportError:
|
|
|
|
return False
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
have_curses = test_for('_curses')
|
|
|
|
have_wx = test_for('wx')
|
|
|
|
have_zi = test_for('zope.interface')
|
|
|
|
have_twisted = test_for('twisted')
|
|
|
|
have_foolscap = test_for('foolscap')
|
|
|
|
have_objc = test_for('objc')
|
|
|
|
have_pexpect = test_for('pexpect')
|
|
|
|
|
2009-03-11 13:49:08 +08:00
|
|
|
# For the IPythonDoctest plugin, we need to exclude certain patterns that cause
|
|
|
|
# testing problems. We should strive to minimize the number of skipped
|
|
|
|
# modules, since this means untested code. As the testing machinery
|
|
|
|
# solidifies, this list should eventually become empty.
|
2009-04-26 00:04:56 +08:00
|
|
|
EXCLUDE = [pjoin('IPython', 'external'),
|
|
|
|
pjoin('IPython', 'frontend', 'process', 'winprocess.py'),
|
|
|
|
pjoin('IPython_doctest_plugin'),
|
|
|
|
pjoin('IPython', 'Gnuplot'),
|
|
|
|
pjoin('IPython', 'Extensions', 'ipy_'),
|
|
|
|
pjoin('IPython', 'Extensions', 'clearcmd'),
|
2009-04-26 01:05:09 +08:00
|
|
|
pjoin('IPython', 'Extensions', 'PhysicalQInteractive'),
|
2009-04-26 00:04:56 +08:00
|
|
|
pjoin('IPython', 'Extensions', 'scitedirector'),
|
|
|
|
pjoin('IPython', 'Extensions', 'numeric_formats'),
|
|
|
|
pjoin('IPython', 'testing', 'attic'),
|
2009-04-26 03:50:43 +08:00
|
|
|
pjoin('IPython', 'testing', 'tutils'),
|
2009-04-26 04:19:34 +08:00
|
|
|
pjoin('IPython', 'testing', 'tools'),
|
|
|
|
pjoin('IPython', 'testing', 'mkdoctests')
|
2009-03-11 13:49:08 +08:00
|
|
|
]
|
|
|
|
|
2009-04-26 03:27:03 +08:00
|
|
|
if not have_wx:
|
2009-04-26 01:05:09 +08:00
|
|
|
EXCLUDE.append(pjoin('IPython', 'Extensions', 'igrid'))
|
2009-04-26 03:27:03 +08:00
|
|
|
EXCLUDE.append(pjoin('IPython', 'gui'))
|
|
|
|
EXCLUDE.append(pjoin('IPython', 'frontend', 'wx'))
|
|
|
|
|
|
|
|
if not have_objc:
|
|
|
|
EXCLUDE.append(pjoin('IPython', 'frontend', 'cocoa'))
|
2009-04-26 01:05:09 +08:00
|
|
|
|
2009-04-26 03:27:03 +08:00
|
|
|
if not have_curses:
|
2009-04-26 01:05:09 +08:00
|
|
|
EXCLUDE.append(pjoin('IPython', 'Extensions', 'ibrowse'))
|
|
|
|
|
2009-04-26 03:27:03 +08:00
|
|
|
if not sys.platform == 'win32':
|
|
|
|
EXCLUDE.append(pjoin('IPython', 'platutils_win32'))
|
|
|
|
|
2009-04-26 04:50:45 +08:00
|
|
|
# These have to be skipped on win32 because the use echo, rm, cd, etc.
|
|
|
|
# See ticket https://bugs.launchpad.net/bugs/366982
|
2009-04-26 04:19:34 +08:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'test_exampleip'))
|
|
|
|
EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'dtexample'))
|
|
|
|
|
2009-04-26 03:27:03 +08:00
|
|
|
if not os.name == 'posix':
|
|
|
|
EXCLUDE.append(pjoin('IPython', 'platutils_posix'))
|
|
|
|
|
|
|
|
if not have_pexpect:
|
2009-07-03 00:12:10 +08:00
|
|
|
EXCLUDE.append(pjoin('IPython', 'lib', 'irunner'))
|
2009-04-26 01:05:09 +08:00
|
|
|
|
|
|
|
# This is needed for the reg-exp to match on win32 in the ipdoctest plugin.
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
EXCLUDE = [s.replace('\\','\\\\') for s in EXCLUDE]
|
|
|
|
|
|
|
|
|
2009-03-11 13:49:08 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Functions and classes
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
def run_iptest():
|
|
|
|
"""Run the IPython test suite using nose.
|
|
|
|
|
|
|
|
This function is called when this script is **not** called with the form
|
|
|
|
`iptest all`. It simply calls nose with appropriate command line flags
|
|
|
|
and accepts all of the standard nose arguments.
|
2008-08-24 14:37:40 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
warnings.filterwarnings('ignore',
|
|
|
|
'This will be removed soon. Use IPython.testing.util instead')
|
|
|
|
|
2009-03-21 12:18:16 +08:00
|
|
|
argv = sys.argv + [
|
|
|
|
# Loading ipdoctest causes problems with Twisted.
|
|
|
|
# I am removing this as a temporary fix to get the
|
|
|
|
# test suite back into working shape. Our nose
|
|
|
|
# plugin needs to be gone through with a fine
|
|
|
|
# toothed comb to find what is causing the problem.
|
2009-04-24 06:29:27 +08:00
|
|
|
'--with-ipdoctest',
|
2009-04-03 17:03:12 +08:00
|
|
|
'--ipdoctest-tests','--ipdoctest-extension=txt',
|
2008-11-09 13:54:34 +08:00
|
|
|
'--detailed-errors',
|
2008-08-24 14:37:40 +08:00
|
|
|
|
2008-11-09 13:54:34 +08:00
|
|
|
# We add --exe because of setuptools' imbecility (it
|
|
|
|
# blindly does chmod +x on ALL files). Nose does the
|
|
|
|
# right thing and it tries to avoid executables,
|
|
|
|
# setuptools unfortunately forces our hand here. This
|
|
|
|
# has been discussed on the distutils list and the
|
|
|
|
# setuptools devs refuse to fix this problem!
|
|
|
|
'--exe',
|
|
|
|
]
|
2008-08-24 14:37:40 +08:00
|
|
|
|
2009-03-11 04:02:00 +08:00
|
|
|
# Detect if any tests were required by explicitly calling an IPython
|
|
|
|
# submodule or giving a specific path
|
|
|
|
has_tests = False
|
2008-08-24 14:37:40 +08:00
|
|
|
for arg in sys.argv:
|
2009-03-11 04:02:00 +08:00
|
|
|
if 'IPython' in arg or arg.endswith('.py') or \
|
|
|
|
(':' in arg and '.py' in arg):
|
|
|
|
has_tests = True
|
2008-08-24 14:37:40 +08:00
|
|
|
break
|
2009-04-03 17:03:12 +08:00
|
|
|
|
2009-03-11 04:02:00 +08:00
|
|
|
# If nothing was specifically requested, test full IPython
|
|
|
|
if not has_tests:
|
2008-08-24 14:37:40 +08:00
|
|
|
argv.append('IPython')
|
|
|
|
|
2009-04-03 17:03:12 +08:00
|
|
|
# Construct list of plugins, omitting the existing doctest plugin, which
|
|
|
|
# ours replaces (and extends).
|
2009-03-11 13:49:08 +08:00
|
|
|
plugins = [IPythonDoctest(EXCLUDE)]
|
2008-11-09 13:54:34 +08:00
|
|
|
for p in nose.plugins.builtin.plugins:
|
|
|
|
plug = p()
|
|
|
|
if plug.name == 'doctest':
|
|
|
|
continue
|
|
|
|
|
|
|
|
#print '*** adding plugin:',plug.name # dbg
|
|
|
|
plugins.append(plug)
|
|
|
|
|
2008-08-24 14:37:40 +08:00
|
|
|
TestProgram(argv=argv,plugins=plugins)
|
2009-04-25 01:12:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
class IPTester(object):
|
|
|
|
"""Call that calls iptest or trial in a subprocess.
|
|
|
|
"""
|
|
|
|
def __init__(self,runner='iptest',params=None):
|
|
|
|
""" """
|
|
|
|
if runner == 'iptest':
|
|
|
|
self.runner = ['iptest','-v']
|
|
|
|
else:
|
2009-04-26 01:05:09 +08:00
|
|
|
self.runner = [find_cmd('trial')]
|
2009-04-25 01:12:50 +08:00
|
|
|
if params is None:
|
|
|
|
params = []
|
|
|
|
if isinstance(params,str):
|
|
|
|
params = [params]
|
|
|
|
self.params = params
|
|
|
|
|
|
|
|
# Assemble call
|
|
|
|
self.call_args = self.runner+self.params
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
"""Run the stored commands"""
|
|
|
|
return subprocess.call(self.call_args)
|
|
|
|
|
|
|
|
|
|
|
|
def make_runners():
|
|
|
|
"""Define the modules and packages that need to be tested.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# This omits additional top-level modules that should not be doctested.
|
|
|
|
# XXX: Shell.py is also ommited because of a bug in the skip_doctest
|
|
|
|
# decorator. See ticket https://bugs.launchpad.net/bugs/366209
|
|
|
|
top_mod = \
|
2009-07-02 07:12:15 +08:00
|
|
|
['backgroundjobs.py', 'coloransi.py', 'completer.py', 'configloader.py',
|
2009-07-02 07:39:48 +08:00
|
|
|
'crashhandler.py', 'debugger.py', 'deepreload.py', 'demo.py',
|
2009-07-02 08:07:30 +08:00
|
|
|
'DPyGetOpt.py', 'dtutils.py', 'excolors.py', 'fakemodule.py',
|
2009-04-25 01:12:50 +08:00
|
|
|
'generics.py', 'genutils.py', 'history.py', 'hooks.py', 'ipapi.py',
|
2009-04-26 03:27:03 +08:00
|
|
|
'iplib.py', 'ipmaker.py', 'ipstruct.py', 'Itpl.py',
|
2009-07-03 00:14:59 +08:00
|
|
|
'logger.py', 'macro.py', 'magic.py', 'OInspect.py',
|
2009-04-25 01:12:50 +08:00
|
|
|
'OutputTrap.py', 'platutils.py', 'prefilter.py', 'Prompts.py',
|
|
|
|
'PyColorize.py', 'Release.py', 'rlineimpl.py', 'shadowns.py',
|
|
|
|
'shellglobals.py', 'strdispatch.py', 'twshell.py',
|
|
|
|
'ultraTB.py', 'upgrade_dir.py', 'usage.py', 'wildcard.py',
|
|
|
|
# See note above for why this is skipped
|
|
|
|
# 'Shell.py',
|
|
|
|
'winconsole.py']
|
|
|
|
|
2009-04-26 03:27:03 +08:00
|
|
|
if have_pexpect:
|
|
|
|
top_mod.append('irunner.py')
|
2009-04-25 01:12:50 +08:00
|
|
|
|
2009-04-26 06:04:17 +08:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
top_mod.append('platutils_win32.py')
|
|
|
|
elif os.name == 'posix':
|
|
|
|
top_mod.append('platutils_posix.py')
|
|
|
|
else:
|
|
|
|
top_mod.append('platutils_dummy.py')
|
|
|
|
|
2009-04-25 01:39:01 +08:00
|
|
|
# These are tested by nose, so skip IPython.kernel
|
2009-04-26 03:27:03 +08:00
|
|
|
top_pack = ['config','Extensions','frontend',
|
2009-04-25 01:12:50 +08:00
|
|
|
'testing','tests','tools','UserConfig']
|
|
|
|
|
2009-04-26 03:27:03 +08:00
|
|
|
if have_wx:
|
|
|
|
top_pack.append('gui')
|
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
modules = ['IPython.%s' % m[:-3] for m in top_mod ]
|
|
|
|
packages = ['IPython.%s' % m for m in top_pack ]
|
|
|
|
|
|
|
|
# Make runners
|
|
|
|
runners = dict(zip(top_pack, [IPTester(params=v) for v in packages]))
|
2009-04-25 02:04:32 +08:00
|
|
|
|
2009-04-25 01:39:01 +08:00
|
|
|
# Test IPython.kernel using trial if twisted is installed
|
2009-04-26 03:27:03 +08:00
|
|
|
if have_zi and have_twisted and have_foolscap:
|
2009-04-25 01:12:50 +08:00
|
|
|
runners['trial'] = IPTester('trial',['IPython'])
|
|
|
|
|
2009-04-25 02:04:32 +08:00
|
|
|
runners['modules'] = IPTester(params=modules)
|
2009-04-25 01:12:50 +08:00
|
|
|
|
|
|
|
return runners
|
|
|
|
|
|
|
|
|
|
|
|
def run_iptestall():
|
|
|
|
"""Run the entire IPython test suite by calling nose and trial.
|
|
|
|
|
|
|
|
This function constructs :class:`IPTester` instances for all IPython
|
|
|
|
modules and package and then runs each of them. This causes the modules
|
|
|
|
and packages of IPython to be tested each in their own subprocess using
|
|
|
|
nose or twisted.trial appropriately.
|
|
|
|
"""
|
|
|
|
runners = make_runners()
|
|
|
|
# Run all test runners, tracking execution time
|
|
|
|
failed = {}
|
|
|
|
t_start = time.time()
|
|
|
|
for name,runner in runners.iteritems():
|
|
|
|
print '*'*77
|
|
|
|
print 'IPython test set:',name
|
|
|
|
res = runner.run()
|
|
|
|
if res:
|
|
|
|
failed[name] = res
|
|
|
|
t_end = time.time()
|
|
|
|
t_tests = t_end - t_start
|
|
|
|
nrunners = len(runners)
|
|
|
|
nfail = len(failed)
|
|
|
|
# summarize results
|
|
|
|
print
|
|
|
|
print '*'*77
|
|
|
|
print 'Ran %s test sets in %.3fs' % (nrunners, t_tests)
|
|
|
|
print
|
|
|
|
if not failed:
|
|
|
|
print 'OK'
|
|
|
|
else:
|
|
|
|
# If anything went wrong, point out what command to rerun manually to
|
|
|
|
# see the actual errors and individual summary
|
|
|
|
print 'ERROR - %s out of %s test sets failed.' % (nfail, nrunners)
|
|
|
|
for name in failed:
|
|
|
|
failed_runner = runners[name]
|
|
|
|
print '-'*40
|
|
|
|
print 'Runner failed:',name
|
|
|
|
print 'You may wish to rerun this one individually, with:'
|
|
|
|
print ' '.join(failed_runner.call_args)
|
|
|
|
print
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2009-04-26 07:09:59 +08:00
|
|
|
if len(sys.argv) == 1:
|
2009-04-25 01:12:50 +08:00
|
|
|
run_iptestall()
|
|
|
|
else:
|
2009-04-26 07:09:59 +08:00
|
|
|
if sys.argv[1] == 'all':
|
|
|
|
run_iptestall()
|
|
|
|
else:
|
|
|
|
run_iptest()
|
2009-04-25 01:12:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|