##// END OF EJS Templates
shellglobals.py => core/shellglobals.py and imports updated.
shellglobals.py => core/shellglobals.py and imports updated.

File last commit:

r2046:af9b6096
r2047:40f9440d
Show More
iptest.py
299 lines | 10.3 KiB | text/x-python | PythonLexer
Fernando Perez
Add module I forgot
r1574 # -*- coding: utf-8 -*-
"""IPython Test Suite Runner.
Fernando Perez
Cleanup testing machinery.
r1851
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 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.
Fernando Perez
Add module I forgot
r1574 """
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
# Module imports
#-----------------------------------------------------------------------------
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 import os
import os.path as path
Fernando Perez
Add module I forgot
r1574 import sys
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 import subprocess
import time
Fernando Perez
Add module I forgot
r1574 import warnings
import nose.plugins.builtin
Fernando Perez
Cleanup testing machinery.
r1851 from nose.core import TestProgram
Fernando Perez
Add module I forgot
r1574
Brian Granger
All platutils modules to utils, moved tests and updated imports.
r2039 from IPython.utils.platutils import find_cmd
Fernando Perez
Add module I forgot
r1574 from IPython.testing.plugin.ipdoctest import IPythonDoctest
Brian Granger
Making the doctest exclude paths os independent.
r1979 pjoin = path.join
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
Administrator
Fixing bugs with the testing system.
r1981 # Logic for skipping doctests
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
Administrator
Fixing bugs with the testing system.
r1981 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')
Fernando Perez
Cleanup testing machinery.
r1851 # 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.
Brian Granger
Making the doctest exclude paths os independent.
r1979 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'),
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980 pjoin('IPython', 'Extensions', 'PhysicalQInteractive'),
Brian Granger
Making the doctest exclude paths os independent.
r1979 pjoin('IPython', 'Extensions', 'scitedirector'),
pjoin('IPython', 'Extensions', 'numeric_formats'),
pjoin('IPython', 'testing', 'attic'),
Brian Granger
Fixing tests in IPython.testing.
r1982 pjoin('IPython', 'testing', 'tutils'),
Administrator
More fixes for testing on win32.
r1984 pjoin('IPython', 'testing', 'tools'),
pjoin('IPython', 'testing', 'mkdoctests')
Fernando Perez
Cleanup testing machinery.
r1851 ]
Administrator
Fixing bugs with the testing system.
r1981 if not have_wx:
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980 EXCLUDE.append(pjoin('IPython', 'Extensions', 'igrid'))
Administrator
Fixing bugs with the testing system.
r1981 EXCLUDE.append(pjoin('IPython', 'gui'))
EXCLUDE.append(pjoin('IPython', 'frontend', 'wx'))
if not have_objc:
EXCLUDE.append(pjoin('IPython', 'frontend', 'cocoa'))
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980
Administrator
Fixing bugs with the testing system.
r1981 if not have_curses:
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980 EXCLUDE.append(pjoin('IPython', 'Extensions', 'ibrowse'))
Administrator
Fixing bugs with the testing system.
r1981 if not sys.platform == 'win32':
EXCLUDE.append(pjoin('IPython', 'platutils_win32'))
Brian Granger
Adding comment about ticket https://bugs.launchpad.net/bugs/366982
r1985 # These have to be skipped on win32 because the use echo, rm, cd, etc.
# See ticket https://bugs.launchpad.net/bugs/366982
Administrator
More fixes for testing on win32.
r1984 if sys.platform == 'win32':
EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'test_exampleip'))
EXCLUDE.append(pjoin('IPython', 'testing', 'plugin', 'dtexample'))
Administrator
Fixing bugs with the testing system.
r1981 if not os.name == 'posix':
EXCLUDE.append(pjoin('IPython', 'platutils_posix'))
if not have_pexpect:
Brian Granger
irunner.py => lib/irunner.py and imports updated.
r2035 EXCLUDE.append(pjoin('IPython', 'lib', 'irunner'))
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980
# 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]
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
# Functions and classes
#-----------------------------------------------------------------------------
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 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.
Fernando Perez
Add module I forgot
r1574 """
warnings.filterwarnings('ignore',
'This will be removed soon. Use IPython.testing.util instead')
Brian Granger
Temporarily disabling the ipdoctest nose plugin....
r1888 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.
Fernando Perez
Reactivate --with-ipdoctest option by default, now that trial is isolated.
r1968 '--with-ipdoctest',
Fernando Perez
- Make ipdoctest a little cleaner by giving it separate option names....
r1910 '--ipdoctest-tests','--ipdoctest-extension=txt',
Fernando Perez
Fixes to testing system: ipdocetst plugin wasn't being properly loaded.
r1761 '--detailed-errors',
Fernando Perez
Add module I forgot
r1574
Fernando Perez
Fixes to testing system: ipdocetst plugin wasn't being properly loaded.
r1761 # 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',
]
Fernando Perez
Add module I forgot
r1574
Fernando Perez
Update decorators and test scripts.
r1848 # Detect if any tests were required by explicitly calling an IPython
# submodule or giving a specific path
has_tests = False
Fernando Perez
Add module I forgot
r1574 for arg in sys.argv:
Fernando Perez
Update decorators and test scripts.
r1848 if 'IPython' in arg or arg.endswith('.py') or \
(':' in arg and '.py' in arg):
has_tests = True
Fernando Perez
Add module I forgot
r1574 break
Fernando Perez
- Make ipdoctest a little cleaner by giving it separate option names....
r1910
Fernando Perez
Update decorators and test scripts.
r1848 # If nothing was specifically requested, test full IPython
if not has_tests:
Fernando Perez
Add module I forgot
r1574 argv.append('IPython')
Fernando Perez
- Make ipdoctest a little cleaner by giving it separate option names....
r1910 # Construct list of plugins, omitting the existing doctest plugin, which
# ours replaces (and extends).
Fernando Perez
Cleanup testing machinery.
r1851 plugins = [IPythonDoctest(EXCLUDE)]
Fernando Perez
Fixes to testing system: ipdocetst plugin wasn't being properly loaded.
r1761 for p in nose.plugins.builtin.plugins:
plug = p()
if plug.name == 'doctest':
continue
#print '*** adding plugin:',plug.name # dbg
plugins.append(plug)
Fernando Perez
Add module I forgot
r1574 TestProgram(argv=argv,plugins=plugins)
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972
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:
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980 self.runner = [find_cmd('trial')]
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 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.
Brian Granger
Shell.py => core/shell.py and imports updated.
r2046 # XXX: shell.py is also ommited because of a bug in the skip_doctest
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 # decorator. See ticket https://bugs.launchpad.net/bugs/366209
top_mod = \
Brian Granger
ConfigLoader.py => config/configloader.py and updated all imports.
r2013 ['backgroundjobs.py', 'coloransi.py', 'completer.py', 'configloader.py',
Brian Granger
deep_reload.py =? lib/deepreload.py and imports updated.
r2016 'crashhandler.py', 'debugger.py', 'deepreload.py', 'demo.py',
Brian Granger
FakeModule.py => core/fakemodule.py and updated tests and imports.
r2020 'DPyGetOpt.py', 'dtutils.py', 'excolors.py', 'fakemodule.py',
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 'generics.py', 'genutils.py', 'history.py', 'hooks.py', 'ipapi.py',
Administrator
Fixing bugs with the testing system.
r1981 'iplib.py', 'ipmaker.py', 'ipstruct.py', 'Itpl.py',
Brian Granger
OInspect.py => core/oinspect.py and imports updated.
r2037 'logger.py', 'macro.py', 'magic.py', 'oinspect.py',
Brian Granger
Prompts.py => core/prompts.py and imports updated.
r2040 'outputtrap.py', 'platutils.py', 'prefilter.py', 'prompts.py',
Brian Granger
Release.py => core/release.py and imports updated.
r2043 'PyColorize.py', 'release.py', 'rlineimpl.py', 'shadowns.py',
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 'shellglobals.py', 'strdispatch.py', 'twshell.py',
'ultraTB.py', 'upgrade_dir.py', 'usage.py', 'wildcard.py',
# See note above for why this is skipped
Brian Granger
Shell.py => core/shell.py and imports updated.
r2046 # 'shell.py',
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 'winconsole.py']
Administrator
Fixing bugs with the testing system.
r1981 if have_pexpect:
top_mod.append('irunner.py')
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972
Administrator
Added platutils.get_long_path_name to expand paths with "~" on win32....
r1986 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')
Brian Granger
Merging Fernando's fixes from his trunk-dev and fixing testing things....
r1973 # These are tested by nose, so skip IPython.kernel
Administrator
Fixing bugs with the testing system.
r1981 top_pack = ['config','Extensions','frontend',
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 'testing','tests','tools','UserConfig']
Administrator
Fixing bugs with the testing system.
r1981 if have_wx:
top_pack.append('gui')
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 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]))
Brian Granger
Run the top level module tests in a single process.
r1974
Brian Granger
Merging Fernando's fixes from his trunk-dev and fixing testing things....
r1973 # Test IPython.kernel using trial if twisted is installed
Administrator
Fixing bugs with the testing system.
r1981 if have_zi and have_twisted and have_foolscap:
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 runners['trial'] = IPTester('trial',['IPython'])
Brian Granger
Run the top level module tests in a single process.
r1974 runners['modules'] = IPTester(params=modules)
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972
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():
Brian Granger
Fixing small bug in iptest. Can now be run as "iptest".
r1990 if len(sys.argv) == 1:
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 run_iptestall()
else:
Brian Granger
Fixing small bug in iptest. Can now be run as "iptest".
r1990 if sys.argv[1] == 'all':
run_iptestall()
else:
run_iptest()
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972
if __name__ == '__main__':
main()