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
|
2011-03-31 14:20:28 +08:00
|
|
|
calling this script (with different arguments) recursively. This
|
2009-04-25 01:12:50 +08:00
|
|
|
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.
|
|
|
|
|
2008-08-24 14:37:40 +08:00
|
|
|
"""
|
|
|
|
|
2009-03-11 13:49:08 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
update copyright to 2011/20xx-2011
Closes #1033 (rebased to prevent recursive merge). Closes #2.
459 *.py files in :
39 empty files
176 files without copyright
36 have copyright but don't cite the dev team
208 have copyright and cite the dev team
-----------------------------------------
0 not up to date (cite dev team but not right year)
FYI, list of files that don't have copyright (and are not empty..)
[
'IPython/config/profile/cluster/ipython_config.py',
'IPython/config/profile/math/ipython_config.py',
'IPython/config/profile/pylab/ipython_config.py',
'IPython/config/profile/pysh/ipython_config.py',
'IPython/config/profile/python3/ipython_config.py',
'IPython/config/profile/sympy/ipython_config.py',
'IPython/core/shadowns.py',
'IPython/core/tests/refbug.py',
'IPython/core/tests/simpleerr.py',
'IPython/core/tests/tclass.py',
'IPython/core/tests/test_application.py',
'IPython/core/tests/test_autocall.py',
'IPython/core/tests/test_completer.py',
'IPython/core/tests/test_fakemodule.py',
'IPython/core/tests/test_formatters.py',
'IPython/core/tests/test_handlers.py',
'IPython/core/tests/test_history.py',
'IPython/core/tests/test_imports.py',
'IPython/core/tests/test_iplib.py',
'IPython/core/tests/test_logger.py',
'IPython/core/tests/test_magic.py',
'IPython/core/tests/test_plugin.py',
'IPython/core/tests/test_prefilter.py',
'IPython/core/tests/test_profile.py',
'IPython/core/tests/test_run.py',
'IPython/core/tests/test_splitinput.py',
'IPython/deathrow/astyle.py',
'IPython/deathrow/dtutils.py',
'IPython/deathrow/Gnuplot2.py',
'IPython/deathrow/GnuplotInteractive.py',
'IPython/deathrow/GnuplotRuntime.py',
'IPython/deathrow/gui/wx/ipshell_nonblocking.py',
'IPython/deathrow/gui/wx/ipython_history.py',
'IPython/deathrow/gui/wx/thread_ex.py',
'IPython/deathrow/ibrowse.py',
'IPython/deathrow/igrid.py',
'IPython/deathrow/ipipe.py',
'IPython/deathrow/ipy_defaults.py',
'IPython/deathrow/ipy_kitcfg.py',
'IPython/deathrow/ipy_legacy.py',
'IPython/deathrow/ipy_p4.py',
'IPython/deathrow/ipy_profile_none.py',
'IPython/deathrow/ipy_profile_numpy.py',
'IPython/deathrow/ipy_profile_scipy.py',
'IPython/deathrow/ipy_profile_sh.py',
'IPython/deathrow/ipy_traits_completer.py',
'IPython/deathrow/ipy_vimserver.py',
'IPython/deathrow/numeric_formats.py',
'IPython/deathrow/oldfrontend/process/__init__.py',
'IPython/deathrow/oldfrontend/wx/ipythonx.py',
'IPython/deathrow/scitedirector.py',
'IPython/deathrow/tests/test_prefilter.py',
'IPython/deathrow/twshell.py',
'IPython/extensions/__init__.py',
'IPython/extensions/autoreload.py',
'IPython/extensions/storemagic.py',
'IPython/extensions/tests/test_autoreload.py',
'IPython/external/__init__.py',
'IPython/external/argparse/__init__.py',
'IPython/external/decorator/__init__.py',
'IPython/external/decorators/__init__.py',
'IPython/external/decorators/_decorators.py',
'IPython/external/decorators/_numpy_testing_noseclasses.py',
'IPython/external/decorators/_numpy_testing_utils.py',
'IPython/external/guid/__init__.py',
'IPython/external/Itpl/__init__.py',
'IPython/external/mglob/__init__.py',
'IPython/external/mglob/_mglob.py',
'IPython/external/path/__init__.py',
'IPython/external/path/_path.py',
'IPython/external/pexpect/__init__.py',
'IPython/external/pyparsing/__init__.py',
'IPython/external/qt.py',
'IPython/external/qt_for_kernel.py',
'IPython/external/simplegeneric/__init__.py',
'IPython/external/simplegeneric/_simplegeneric.py',
'IPython/frontend/html/notebook/__init__.py',
'IPython/frontend/html/notebook/tests/test_kernelsession.py',
'IPython/frontend/qt/base_frontend_mixin.py',
'IPython/frontend/qt/console/ansi_code_processor.py',
'IPython/frontend/qt/console/bracket_matcher.py',
'IPython/frontend/qt/console/call_tip_widget.py',
'IPython/frontend/qt/console/completion_lexer.py',
'IPython/frontend/qt/console/completion_widget.py',
'IPython/frontend/qt/console/console_widget.py',
'IPython/frontend/qt/console/history_console_widget.py',
'IPython/frontend/qt/console/ipython_widget.py',
'IPython/frontend/qt/console/kill_ring.py',
'IPython/frontend/qt/console/mainwindow.py',
'IPython/frontend/qt/console/pygments_highlighter.py',
'IPython/frontend/qt/console/qtconsoleapp.py',
'IPython/frontend/qt/console/rich_ipython_widget.py',
'IPython/frontend/qt/console/styles.py',
'IPython/frontend/qt/console/tests/test_ansi_code_processor.py',
'IPython/frontend/qt/console/tests/test_completion_lexer.py',
'IPython/frontend/qt/console/tests/test_kill_ring.py',
'IPython/frontend/qt/kernelmanager.py',
'IPython/frontend/qt/rich_text.py',
'IPython/frontend/qt/svg.py',
'IPython/frontend/qt/util.py',
'IPython/kernel/__init__.py',
'IPython/lib/clipboard.py',
'IPython/lib/display.py',
'IPython/lib/irunner.py',
'IPython/lib/security.py',
'IPython/lib/tests/test_imports.py',
'IPython/lib/tests/test_irunner.py',
'IPython/lib/tests/test_irunner_pylab_magic.py',
'IPython/lib/tests/test_security.py',
'IPython/nbformat/v1/tests/nbexamples.py',
'IPython/nbformat/v1/tests/test_json.py',
'IPython/nbformat/v1/tests/test_nbbase.py',
'IPython/nbformat/v2/tests/nbexamples.py',
'IPython/nbformat/v2/tests/test_json.py',
'IPython/nbformat/v2/tests/test_nbbase.py',
'IPython/nbformat/v2/tests/test_nbpy.py',
'IPython/quarantine/clearcmd.py',
'IPython/quarantine/envpersist.py',
'IPython/quarantine/ext_rescapture.py',
'IPython/quarantine/ipy_app_completers.py',
'IPython/quarantine/ipy_completers.py',
'IPython/quarantine/ipy_editors.py',
'IPython/quarantine/ipy_exportdb.py',
'IPython/quarantine/ipy_extutil.py',
'IPython/quarantine/ipy_fsops.py',
'IPython/quarantine/ipy_gnuglobal.py',
'IPython/quarantine/ipy_jot.py',
'IPython/quarantine/ipy_lookfor.py',
'IPython/quarantine/ipy_profile_doctest.py',
'IPython/quarantine/ipy_pydb.py',
'IPython/quarantine/ipy_rehashdir.py',
'IPython/quarantine/ipy_render.py',
'IPython/quarantine/ipy_server.py',
'IPython/quarantine/ipy_signals.py',
'IPython/quarantine/ipy_synchronize_with.py',
'IPython/quarantine/ipy_system_conf.py',
'IPython/quarantine/ipy_which.py',
'IPython/quarantine/ipy_winpdb.py',
'IPython/quarantine/ipy_workdir.py',
'IPython/quarantine/jobctrl.py',
'IPython/quarantine/ledit.py',
'IPython/quarantine/win32clip.py',
'IPython/testing/mkdoctests.py',
'IPython/testing/plugin/dtexample.py',
'IPython/testing/plugin/ipdoctest.py',
'IPython/testing/plugin/iptest.py',
'IPython/testing/plugin/setup.py',
'IPython/testing/plugin/show_refs.py',
'IPython/testing/plugin/simple.py',
'IPython/testing/plugin/simplevars.py',
'IPython/testing/plugin/test_ipdoctest.py',
'IPython/testing/plugin/test_refs.py',
'IPython/testing/skipdoctest.py',
'IPython/testing/tests/test_decorators.py',
'IPython/utils/autoattr.py',
'IPython/utils/nested_context.py',
'IPython/utils/pickleshare.py',
'IPython/utils/py3compat.py',
'IPython/utils/PyColorize.py',
'IPython/utils/rlineimpl.py',
'IPython/utils/strdispatch.py',
'IPython/utils/tempdir.py',
'IPython/utils/tests/test_imports.py',
'IPython/utils/tests/test_wildcard.py',
'IPython/utils/upgradedir.py',
'IPython/zmq/completer.py',
'IPython/zmq/displayhook.py',
'IPython/zmq/entry_point.py',
'IPython/zmq/frontend.py',
'IPython/zmq/iostream.py',
'IPython/zmq/ipkernel.py',
'IPython/zmq/log.py',
'IPython/zmq/parentpoller.py',
'IPython/zmq/pykernel.py',
'IPython/zmq/pylab/backend_inline.py',
'IPython/zmq/zmqshell.py'
]
2011-11-23 22:26:28 +08:00
|
|
|
# Copyright (C) 2009-2011 The IPython Development Team
|
2010-01-30 08:24:13 +08:00
|
|
|
#
|
|
|
|
# Distributed under the terms of the BSD License. The full license is in
|
|
|
|
# the file COPYING, distributed as part of this software.
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Imports
|
2009-03-11 13:49:08 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
2010-01-13 04:42:23 +08:00
|
|
|
# Stdlib
|
2009-04-25 01:12:50 +08:00
|
|
|
import os
|
|
|
|
import os.path as path
|
2010-01-08 08:47:46 +08:00
|
|
|
import signal
|
2008-08-24 14:37:40 +08:00
|
|
|
import sys
|
2009-04-25 01:12:50 +08:00
|
|
|
import subprocess
|
2009-08-02 08:08:32 +08:00
|
|
|
import tempfile
|
2009-04-25 01:12:50 +08:00
|
|
|
import time
|
2008-08-24 14:37:40 +08:00
|
|
|
import warnings
|
|
|
|
|
2010-01-13 04:42:23 +08:00
|
|
|
# Note: monkeypatch!
|
|
|
|
# We need to monkeypatch a small problem in nose itself first, before importing
|
|
|
|
# it for actual use. This should get into nose upstream, but its release cycle
|
|
|
|
# is slow and we need it for our parametric tests to work correctly.
|
2010-01-15 17:06:34 +08:00
|
|
|
from IPython.testing import nosepatch
|
2010-01-13 04:42:23 +08:00
|
|
|
# Now, proceed to import nose itself
|
2008-08-24 14:37:40 +08:00
|
|
|
import nose.plugins.builtin
|
2012-02-10 03:52:20 +08:00
|
|
|
from nose.plugins.xunit import Xunit
|
|
|
|
from nose import SkipTest
|
2009-03-11 13:49:08 +08:00
|
|
|
from nose.core import TestProgram
|
2008-08-24 14:37:40 +08:00
|
|
|
|
2010-01-13 04:42:23 +08:00
|
|
|
# Our own imports
|
2011-09-24 07:57:40 +08:00
|
|
|
from IPython.utils.importstring import import_item
|
2010-01-30 08:24:13 +08:00
|
|
|
from IPython.utils.path import get_ipython_module_path
|
|
|
|
from IPython.utils.process import find_cmd, pycmd2argv
|
|
|
|
from IPython.utils.sysinfo import sys_info
|
|
|
|
|
2010-01-15 17:06:34 +08:00
|
|
|
from IPython.testing import globalipapp
|
|
|
|
from IPython.testing.plugin.ipdoctest import IPythonDoctest
|
2012-02-10 03:52:20 +08:00
|
|
|
from IPython.external.decorators import KnownFailure, knownfailureif
|
2008-08-24 14:37:40 +08:00
|
|
|
|
2009-04-26 00:04:56 +08:00
|
|
|
pjoin = path.join
|
|
|
|
|
2010-01-18 05:13:21 +08:00
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Globals
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Warnings control
|
|
|
|
#-----------------------------------------------------------------------------
|
2010-02-01 04:06:20 +08:00
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
# Twisted generates annoying warnings with Python 2.6, as will do other code
|
|
|
|
# that imports 'sets' as of today
|
|
|
|
warnings.filterwarnings('ignore', 'the sets module is deprecated',
|
|
|
|
DeprecationWarning )
|
|
|
|
|
2010-01-13 15:21:21 +08:00
|
|
|
# This one also comes from Twisted
|
|
|
|
warnings.filterwarnings('ignore', 'the sha module is deprecated',
|
|
|
|
DeprecationWarning)
|
|
|
|
|
2010-01-16 06:41:10 +08:00
|
|
|
# Wx on Fedora11 spits these out
|
|
|
|
warnings.filterwarnings('ignore', 'wxPython/wxWidgets release number mismatch',
|
|
|
|
UserWarning)
|
|
|
|
|
2012-02-10 03:52:20 +08:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Monkeypatch Xunit to count known failures as skipped.
|
|
|
|
# ------------------------------------------------------------------------------
|
2012-02-10 04:20:19 +08:00
|
|
|
def monkeypatch_xunit():
|
2012-02-10 03:52:20 +08:00
|
|
|
try:
|
|
|
|
knownfailureif(True)(lambda: None)()
|
|
|
|
except Exception as e:
|
|
|
|
KnownFailureTest = type(e)
|
|
|
|
|
|
|
|
def addError(self, test, err, capt=None):
|
|
|
|
if issubclass(err[0], KnownFailureTest):
|
|
|
|
err = (SkipTest,) + err[1:]
|
|
|
|
return self.orig_addError(test, err, capt)
|
|
|
|
|
|
|
|
Xunit.orig_addError = Xunit.addError
|
|
|
|
Xunit.addError = addError
|
|
|
|
|
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
|
|
|
#-----------------------------------------------------------------------------
|
2011-09-24 07:57:40 +08:00
|
|
|
def extract_version(mod):
|
|
|
|
return mod.__version__
|
2009-03-11 13:49:08 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
def test_for(item, min_version=None, callback=extract_version):
|
|
|
|
"""Test to see if item is importable, and optionally check against a minimum
|
|
|
|
version.
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
If min_version is given, the default behavior is to check against the
|
|
|
|
`__version__` attribute of the item, but specifying `callback` allows you to
|
|
|
|
extract the value you are interested in. e.g::
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
In [1]: import sys
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
In [2]: from IPython.testing.iptest import test_for
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info)
|
|
|
|
Out[3]: True
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
"""
|
2009-04-26 03:27:03 +08:00
|
|
|
try:
|
2011-09-24 07:57:40 +08:00
|
|
|
check = import_item(item)
|
2010-01-17 06:50:08 +08:00
|
|
|
except (ImportError, RuntimeError):
|
2011-09-24 07:57:40 +08:00
|
|
|
# GTK reports Runtime error if it can't be initialized even if it's
|
2010-01-17 06:50:08 +08:00
|
|
|
# importable.
|
2009-04-26 03:27:03 +08:00
|
|
|
return False
|
|
|
|
else:
|
2011-02-28 13:06:02 +08:00
|
|
|
if min_version:
|
2011-09-24 07:57:40 +08:00
|
|
|
if callback:
|
|
|
|
# extra processing step to get version to compare
|
|
|
|
check = callback(check)
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
return check >= min_version
|
2011-02-28 13:06:02 +08:00
|
|
|
else:
|
|
|
|
return True
|
2009-04-26 03:27:03 +08:00
|
|
|
|
2010-01-18 06:36:19 +08:00
|
|
|
# Global dict where we can store information on what we have and what we don't
|
|
|
|
# have available at test run time
|
|
|
|
have = {}
|
|
|
|
|
|
|
|
have['curses'] = test_for('_curses')
|
2011-04-11 15:22:11 +08:00
|
|
|
have['matplotlib'] = test_for('matplotlib')
|
2011-09-24 07:57:40 +08:00
|
|
|
have['pexpect'] = test_for('IPython.external.pexpect')
|
2011-04-11 15:22:11 +08:00
|
|
|
have['pymongo'] = test_for('pymongo')
|
2010-01-18 06:36:19 +08:00
|
|
|
have['wx'] = test_for('wx')
|
|
|
|
have['wx.aui'] = test_for('wx.aui')
|
2011-04-14 03:19:12 +08:00
|
|
|
have['qt'] = test_for('IPython.external.qt')
|
2011-10-21 01:36:10 +08:00
|
|
|
have['sqlite3'] = test_for('sqlite3')
|
2011-09-24 06:03:16 +08:00
|
|
|
|
2011-09-24 07:57:40 +08:00
|
|
|
have['tornado'] = test_for('tornado.version_info', (2,1,0), callback=None)
|
|
|
|
|
|
|
|
if os.name == 'nt':
|
|
|
|
min_zmq = (2,1,7)
|
2011-09-24 06:03:16 +08:00
|
|
|
else:
|
2011-09-24 07:57:40 +08:00
|
|
|
min_zmq = (2,1,4)
|
|
|
|
|
|
|
|
def version_tuple(mod):
|
|
|
|
"turn '2.1.9' into (2,1,9), and '2.1dev' into (2,1,999)"
|
|
|
|
# turn 'dev' into 999, because Python3 rejects str-int comparisons
|
|
|
|
vs = mod.__version__.replace('dev', '.999')
|
|
|
|
tup = tuple([int(v) for v in vs.split('.') ])
|
|
|
|
return tup
|
|
|
|
|
|
|
|
have['zmq'] = test_for('zmq', min_zmq, version_tuple)
|
2009-04-26 03:27:03 +08:00
|
|
|
|
2010-01-18 05:13:21 +08:00
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Functions and classes
|
|
|
|
#-----------------------------------------------------------------------------
|
2009-04-26 01:05:09 +08:00
|
|
|
|
2010-01-18 06:36:19 +08:00
|
|
|
def report():
|
|
|
|
"""Return a string with a summary report of test-related variables."""
|
|
|
|
|
2010-10-27 14:16:59 +08:00
|
|
|
out = [ sys_info(), '\n']
|
2010-01-18 06:36:19 +08:00
|
|
|
|
|
|
|
avail = []
|
|
|
|
not_avail = []
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-18 06:36:19 +08:00
|
|
|
for k, is_avail in have.items():
|
|
|
|
if is_avail:
|
|
|
|
avail.append(k)
|
|
|
|
else:
|
|
|
|
not_avail.append(k)
|
|
|
|
|
|
|
|
if avail:
|
|
|
|
out.append('\nTools and libraries available at test time:\n')
|
|
|
|
avail.sort()
|
|
|
|
out.append(' ' + ' '.join(avail)+'\n')
|
|
|
|
|
|
|
|
if not_avail:
|
|
|
|
out.append('\nTools and libraries NOT available at test time:\n')
|
|
|
|
not_avail.sort()
|
|
|
|
out.append(' ' + ' '.join(not_avail)+'\n')
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-18 06:36:19 +08:00
|
|
|
return ''.join(out)
|
|
|
|
|
|
|
|
|
2009-07-28 06:38:27 +08:00
|
|
|
def make_exclude():
|
2010-01-13 09:36:00 +08:00
|
|
|
"""Make patterns of modules and packages to exclude from testing.
|
2010-02-01 04:06:20 +08:00
|
|
|
|
2010-01-13 09:36:00 +08:00
|
|
|
For the IPythonDoctest plugin, we need to exclude certain patterns that
|
|
|
|
cause testing problems. We should strive to minimize the number of
|
2010-02-01 04:06:20 +08:00
|
|
|
skipped modules, since this means untested code.
|
|
|
|
|
2010-01-13 09:36:00 +08:00
|
|
|
These modules and packages will NOT get scanned by nose at all for tests.
|
|
|
|
"""
|
|
|
|
# Simple utility to make IPython paths more readably, we need a lot of
|
|
|
|
# these below
|
|
|
|
ipjoin = lambda *paths: pjoin('IPython', *paths)
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-13 09:36:00 +08:00
|
|
|
exclusions = [ipjoin('external'),
|
2010-01-10 09:55:56 +08:00
|
|
|
pjoin('IPython_doctest_plugin'),
|
2010-01-13 09:36:00 +08:00
|
|
|
ipjoin('quarantine'),
|
|
|
|
ipjoin('deathrow'),
|
|
|
|
ipjoin('testing', 'attic'),
|
2010-01-13 15:21:21 +08:00
|
|
|
# This guy is probably attic material
|
2010-01-13 09:36:00 +08:00
|
|
|
ipjoin('testing', 'mkdoctests'),
|
2010-01-13 15:21:21 +08:00
|
|
|
# Testing inputhook will need a lot of thought, to figure out
|
|
|
|
# how to have tests that don't lock up with the gui event
|
|
|
|
# loops in the picture
|
2010-01-13 09:36:00 +08:00
|
|
|
ipjoin('lib', 'inputhook'),
|
2010-01-10 09:55:56 +08:00
|
|
|
# Config files aren't really importable stand-alone
|
2010-01-13 09:36:00 +08:00
|
|
|
ipjoin('config', 'default'),
|
|
|
|
ipjoin('config', 'profile'),
|
2010-01-10 09:55:56 +08:00
|
|
|
]
|
2011-10-21 01:36:10 +08:00
|
|
|
if not have['sqlite3']:
|
|
|
|
exclusions.append(ipjoin('core', 'tests', 'test_history'))
|
|
|
|
exclusions.append(ipjoin('core', 'history'))
|
2010-01-18 06:36:19 +08:00
|
|
|
if not have['wx']:
|
2010-01-13 09:36:00 +08:00
|
|
|
exclusions.append(ipjoin('lib', 'inputhookwx'))
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-03-25 07:42:04 +08:00
|
|
|
# We do this unconditionally, so that the test suite doesn't import
|
|
|
|
# gtk, changing the default encoding and masking some unicode bugs.
|
|
|
|
exclusions.append(ipjoin('lib', 'inputhookgtk'))
|
2009-07-28 06:52:00 +08:00
|
|
|
|
2009-07-28 06:38:27 +08:00
|
|
|
# These have to be skipped on win32 because the use echo, rm, cd, etc.
|
2011-05-30 06:10:48 +08:00
|
|
|
# See ticket https://github.com/ipython/ipython/issues/87
|
2009-07-28 06:38:27 +08:00
|
|
|
if sys.platform == 'win32':
|
2010-01-13 09:36:00 +08:00
|
|
|
exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip'))
|
|
|
|
exclusions.append(ipjoin('testing', 'plugin', 'dtexample'))
|
2009-07-28 06:38:27 +08:00
|
|
|
|
2010-01-18 06:36:19 +08:00
|
|
|
if not have['pexpect']:
|
2010-01-13 09:39:42 +08:00
|
|
|
exclusions.extend([ipjoin('scripts', 'irunner'),
|
2011-04-14 03:19:12 +08:00
|
|
|
ipjoin('lib', 'irunner'),
|
2011-12-13 03:47:51 +08:00
|
|
|
ipjoin('lib', 'tests', 'test_irunner'),
|
|
|
|
ipjoin('frontend', 'terminal', 'console'),
|
|
|
|
])
|
2009-07-28 06:38:27 +08:00
|
|
|
|
2011-02-28 13:06:02 +08:00
|
|
|
if not have['zmq']:
|
|
|
|
exclusions.append(ipjoin('zmq'))
|
2011-04-14 03:19:12 +08:00
|
|
|
exclusions.append(ipjoin('frontend', 'qt'))
|
2011-12-13 03:47:51 +08:00
|
|
|
exclusions.append(ipjoin('frontend', 'html'))
|
|
|
|
exclusions.append(ipjoin('frontend', 'consoleapp.py'))
|
|
|
|
exclusions.append(ipjoin('frontend', 'terminal', 'console'))
|
2011-04-07 05:54:33 +08:00
|
|
|
exclusions.append(ipjoin('parallel'))
|
2011-04-14 03:19:12 +08:00
|
|
|
elif not have['qt']:
|
|
|
|
exclusions.append(ipjoin('frontend', 'qt'))
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-04-08 08:50:07 +08:00
|
|
|
if not have['pymongo']:
|
|
|
|
exclusions.append(ipjoin('parallel', 'controller', 'mongodb'))
|
2011-05-05 08:06:30 +08:00
|
|
|
exclusions.append(ipjoin('parallel', 'tests', 'test_mongodb'))
|
2011-02-28 13:06:02 +08:00
|
|
|
|
2011-04-11 15:22:11 +08:00
|
|
|
if not have['matplotlib']:
|
2011-11-27 16:28:26 +08:00
|
|
|
exclusions.extend([ipjoin('core', 'pylabtools'),
|
|
|
|
ipjoin('core', 'tests', 'test_pylabtools')])
|
2011-04-11 15:22:11 +08:00
|
|
|
|
2011-08-31 00:39:57 +08:00
|
|
|
if not have['tornado']:
|
|
|
|
exclusions.append(ipjoin('frontend', 'html'))
|
|
|
|
|
2009-07-28 06:38:27 +08:00
|
|
|
# This is needed for the reg-exp to match on win32 in the ipdoctest plugin.
|
|
|
|
if sys.platform == 'win32':
|
2010-01-10 08:30:59 +08:00
|
|
|
exclusions = [s.replace('\\','\\\\') for s in exclusions]
|
2009-07-28 06:38:27 +08:00
|
|
|
|
2010-01-10 08:30:59 +08:00
|
|
|
return exclusions
|
2009-04-26 01:05:09 +08:00
|
|
|
|
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
class IPTester(object):
|
|
|
|
"""Call that calls iptest or trial in a subprocess.
|
|
|
|
"""
|
2010-01-08 08:47:46 +08:00
|
|
|
#: string, name of test runner that will be called
|
|
|
|
runner = None
|
|
|
|
#: list, parameters for test runner
|
|
|
|
params = None
|
|
|
|
#: list, arguments of system call to be made to call test runner
|
|
|
|
call_args = None
|
|
|
|
#: list, process ids of subprocesses we start (for cleanup)
|
|
|
|
pids = None
|
2012-01-26 06:25:44 +08:00
|
|
|
#: str, coverage xml output file
|
|
|
|
coverage_xml = None
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-15 17:06:34 +08:00
|
|
|
def __init__(self, runner='iptest', params=None):
|
2010-01-08 08:47:46 +08:00
|
|
|
"""Create new test runner."""
|
2010-01-18 05:13:21 +08:00
|
|
|
p = os.path
|
2010-01-08 08:04:08 +08:00
|
|
|
if runner == 'iptest':
|
2010-01-31 11:43:46 +08:00
|
|
|
iptest_app = get_ipython_module_path('IPython.testing.iptest')
|
|
|
|
self.runner = pycmd2argv(iptest_app) + sys.argv[1:]
|
2010-02-01 04:06:20 +08:00
|
|
|
else:
|
|
|
|
raise Exception('Not a valid test runner: %s' % repr(runner))
|
2010-01-08 08:04:08 +08:00
|
|
|
if params is None:
|
|
|
|
params = []
|
2010-01-15 17:06:34 +08:00
|
|
|
if isinstance(params, str):
|
2010-01-08 08:04:08 +08:00
|
|
|
params = [params]
|
|
|
|
self.params = params
|
|
|
|
|
|
|
|
# Assemble call
|
|
|
|
self.call_args = self.runner+self.params
|
2012-01-25 05:23:58 +08:00
|
|
|
|
2012-01-27 19:16:35 +08:00
|
|
|
# Find the section we're testing (IPython.foo)
|
|
|
|
for sect in self.params:
|
|
|
|
if sect.startswith('IPython'): break
|
|
|
|
else:
|
|
|
|
raise ValueError("Section not found", self.params)
|
|
|
|
|
2012-01-25 05:23:58 +08:00
|
|
|
if '--with-xunit' in self.call_args:
|
|
|
|
self.call_args.append('--xunit-file=%s' % path.abspath(sect+'.xunit.xml'))
|
2012-01-26 06:25:44 +08:00
|
|
|
|
2012-01-27 03:01:43 +08:00
|
|
|
if '--with-xml-coverage' in self.call_args:
|
2012-01-26 06:25:44 +08:00
|
|
|
self.coverage_xml = path.abspath(sect+".coverage.xml")
|
2012-01-27 03:01:43 +08:00
|
|
|
self.call_args.remove('--with-xml-coverage')
|
2012-01-26 06:29:03 +08:00
|
|
|
self.call_args = ["coverage", "run", "--source="+sect] + self.call_args[1:]
|
2010-01-08 08:04:08 +08:00
|
|
|
|
2010-01-08 08:47:46 +08:00
|
|
|
# Store pids of anything we start to clean up on deletion, if possible
|
|
|
|
# (on posix only, since win32 has no os.kill)
|
|
|
|
self.pids = []
|
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
def _run_cmd(self):
|
|
|
|
# On Windows, use os.system instead of subprocess.call, because I
|
|
|
|
# was having problems with subprocess and I just don't know enough
|
|
|
|
# about win32 to debug this reliably. Os.system may be the 'old
|
|
|
|
# fashioned' way to do it, but it works just fine. If someone
|
|
|
|
# later can clean this up that's fine, as long as the tests run
|
|
|
|
# reliably in win32.
|
2010-02-01 04:06:20 +08:00
|
|
|
# What types of problems are you having. They may be related to
|
|
|
|
# running Python in unboffered mode. BG.
|
2010-01-08 08:04:08 +08:00
|
|
|
return os.system(' '.join(self.call_args))
|
|
|
|
else:
|
|
|
|
def _run_cmd(self):
|
2010-08-18 09:38:39 +08:00
|
|
|
# print >> sys.stderr, '*** CMD:', ' '.join(self.call_args) # dbg
|
2010-01-08 08:47:46 +08:00
|
|
|
subp = subprocess.Popen(self.call_args)
|
|
|
|
self.pids.append(subp.pid)
|
|
|
|
# If this fails, the pid will be left in self.pids and cleaned up
|
|
|
|
# later, but if the wait call succeeds, then we can clear the
|
|
|
|
# stored pid.
|
|
|
|
retcode = subp.wait()
|
|
|
|
self.pids.pop()
|
|
|
|
return retcode
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
def run(self):
|
|
|
|
"""Run the stored commands"""
|
|
|
|
try:
|
2012-01-26 06:25:44 +08:00
|
|
|
retcode = self._run_cmd()
|
2010-01-08 08:04:08 +08:00
|
|
|
except:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
return 1 # signal failure
|
2012-01-26 06:25:44 +08:00
|
|
|
|
|
|
|
if self.coverage_xml:
|
2012-01-27 03:03:00 +08:00
|
|
|
subprocess.call(["coverage", "xml", "-o", self.coverage_xml])
|
2012-01-26 06:25:44 +08:00
|
|
|
return retcode
|
2010-01-08 08:04:08 +08:00
|
|
|
|
2010-01-08 08:47:46 +08:00
|
|
|
def __del__(self):
|
|
|
|
"""Cleanup on exit by killing any leftover processes."""
|
|
|
|
|
|
|
|
if not hasattr(os, 'kill'):
|
|
|
|
return
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-08 08:47:46 +08:00
|
|
|
for pid in self.pids:
|
|
|
|
try:
|
|
|
|
print 'Cleaning stale PID:', pid
|
|
|
|
os.kill(pid, signal.SIGKILL)
|
|
|
|
except OSError:
|
|
|
|
# This is just a best effort, if we fail or the process was
|
|
|
|
# really gone, ignore it.
|
2011-10-04 22:14:41 +08:00
|
|
|
pass
|
2010-01-08 09:39:24 +08:00
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
|
|
|
|
def make_runners():
|
|
|
|
"""Define the top-level packages that need to be tested.
|
|
|
|
"""
|
|
|
|
|
2010-01-16 06:41:10 +08:00
|
|
|
# Packages to be tested via nose, that only depend on the stdlib
|
|
|
|
nose_pkg_names = ['config', 'core', 'extensions', 'frontend', 'lib',
|
2011-07-30 01:15:22 +08:00
|
|
|
'scripts', 'testing', 'utils', 'nbformat' ]
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2011-04-07 12:34:12 +08:00
|
|
|
if have['zmq']:
|
|
|
|
nose_pkg_names.append('parallel')
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-16 06:41:10 +08:00
|
|
|
# For debugging this code, only load quick stuff
|
2010-01-18 05:13:21 +08:00
|
|
|
#nose_pkg_names = ['core', 'extensions'] # dbg
|
2010-01-16 06:41:10 +08:00
|
|
|
|
|
|
|
# Make fully qualified package names prepending 'IPython.' to our name lists
|
|
|
|
nose_packages = ['IPython.%s' % m for m in nose_pkg_names ]
|
|
|
|
|
|
|
|
# Make runners
|
|
|
|
runners = [ (v, IPTester('iptest', params=v)) for v in nose_packages ]
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
return runners
|
|
|
|
|
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
def run_iptest():
|
|
|
|
"""Run the IPython test suite using nose.
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
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
|
|
|
"""
|
2012-02-10 04:20:19 +08:00
|
|
|
# Apply our monkeypatch to Xunit
|
|
|
|
if not hasattr(Xunit, 'orig_addError'):
|
|
|
|
monkeypatch_xunit()
|
2008-08-24 14:37:40 +08:00
|
|
|
|
2011-10-04 22:14:41 +08:00
|
|
|
warnings.filterwarnings('ignore',
|
2008-08-24 14:37:40 +08:00
|
|
|
'This will be removed soon. Use IPython.testing.util instead')
|
|
|
|
|
2010-01-17 06:43:41 +08:00
|
|
|
argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2010-01-10 08:30:59 +08:00
|
|
|
# Loading ipdoctest causes problems with Twisted, but
|
|
|
|
# our test suite runner now separates things and runs
|
|
|
|
# all Twisted tests with trial.
|
|
|
|
'--with-ipdoctest',
|
|
|
|
'--ipdoctest-tests','--ipdoctest-extension=txt',
|
2011-10-04 22:14:41 +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
|
|
|
|
2010-01-18 05:13:21 +08:00
|
|
|
if nose.__version__ >= '0.11':
|
|
|
|
# I don't fully understand why we need this one, but depending on what
|
|
|
|
# directory the test suite is run from, if we don't give it, 0 tests
|
|
|
|
# get run. Specifically, if the test suite is run from the source dir
|
|
|
|
# with an argument (like 'iptest.py IPython.core', 0 tests are run,
|
|
|
|
# even if the same call done in this directory works fine). It appears
|
|
|
|
# that if the requested package is in the current dir, nose bails early
|
|
|
|
# by default. Since it's otherwise harmless, leave it in by default
|
|
|
|
# for nose >= 0.11, though unfortunately nose 0.10 doesn't support it.
|
|
|
|
argv.append('--traverse-namespace')
|
2008-08-24 14:37:40 +08:00
|
|
|
|
2011-08-07 10:54:42 +08:00
|
|
|
# use our plugin for doctesting. It will remove the standard doctest plugin
|
|
|
|
# if it finds it enabled
|
2011-04-04 08:49:40 +08:00
|
|
|
plugins = [IPythonDoctest(make_exclude()), KnownFailure()]
|
2010-01-10 08:30:59 +08:00
|
|
|
# We need a global ipython running in this process
|
|
|
|
globalipapp.start_ipython()
|
|
|
|
# Now nose can run
|
2011-08-07 10:54:42 +08:00
|
|
|
TestProgram(argv=argv, addplugins=plugins)
|
2009-04-25 01:12:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
def run_iptestall():
|
|
|
|
"""Run the entire IPython test suite by calling nose and trial.
|
2011-10-04 22:14:41 +08:00
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
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.
|
|
|
|
"""
|
2009-07-28 06:38:27 +08:00
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
runners = make_runners()
|
2009-07-28 06:38:27 +08:00
|
|
|
|
2010-01-08 08:04:08 +08:00
|
|
|
# Run the test runners in a temporary dir so we can nuke it when finished
|
|
|
|
# to clean up any junk files left over by accident. This also makes it
|
|
|
|
# robust against being run in non-writeable directories by mistake, as the
|
|
|
|
# temp dir will always be user-writeable.
|
2011-07-13 01:19:38 +08:00
|
|
|
curdir = os.getcwdu()
|
2010-01-08 08:04:08 +08:00
|
|
|
testdir = tempfile.gettempdir()
|
|
|
|
os.chdir(testdir)
|
|
|
|
|
2009-04-25 01:12:50 +08:00
|
|
|
# Run all test runners, tracking execution time
|
2010-01-15 17:06:34 +08:00
|
|
|
failed = []
|
2009-04-25 01:12:50 +08:00
|
|
|
t_start = time.time()
|
2010-01-08 08:04:08 +08:00
|
|
|
try:
|
2010-01-15 17:06:34 +08:00
|
|
|
for (name, runner) in runners:
|
|
|
|
print '*'*70
|
2010-01-08 08:04:08 +08:00
|
|
|
print 'IPython test group:',name
|
|
|
|
res = runner.run()
|
|
|
|
if res:
|
2010-01-15 17:06:34 +08:00
|
|
|
failed.append( (name, runner) )
|
2010-01-08 08:04:08 +08:00
|
|
|
finally:
|
|
|
|
os.chdir(curdir)
|
2009-04-25 01:12:50 +08:00
|
|
|
t_end = time.time()
|
|
|
|
t_tests = t_end - t_start
|
|
|
|
nrunners = len(runners)
|
|
|
|
nfail = len(failed)
|
|
|
|
# summarize results
|
|
|
|
print
|
2010-01-15 17:06:34 +08:00
|
|
|
print '*'*70
|
2010-01-18 06:36:19 +08:00
|
|
|
print 'Test suite completed for system with the following information:'
|
|
|
|
print report()
|
2009-07-29 17:13:26 +08:00
|
|
|
print 'Ran %s test groups in %.3fs' % (nrunners, t_tests)
|
2009-04-25 01:12:50 +08:00
|
|
|
print
|
2010-01-18 06:36:19 +08:00
|
|
|
print 'Status:'
|
2009-04-25 01:12:50 +08:00
|
|
|
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
|
2009-07-29 17:13:26 +08:00
|
|
|
print 'ERROR - %s out of %s test groups failed.' % (nfail, nrunners)
|
2010-01-15 17:06:34 +08:00
|
|
|
for name, failed_runner in failed:
|
2009-04-25 01:12:50 +08:00
|
|
|
print '-'*40
|
|
|
|
print 'Runner failed:',name
|
|
|
|
print 'You may wish to rerun this one individually, with:'
|
|
|
|
print ' '.join(failed_runner.call_args)
|
|
|
|
print
|
2011-05-25 02:21:45 +08:00
|
|
|
# Ensure that our exit code indicates failure
|
|
|
|
sys.exit(1)
|
2009-04-25 01:12:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2010-01-15 17:06:34 +08:00
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if arg.startswith('IPython'):
|
2010-01-15 18:00:11 +08:00
|
|
|
# This is in-process
|
2009-04-26 07:09:59 +08:00
|
|
|
run_iptest()
|
2010-01-15 17:06:34 +08:00
|
|
|
else:
|
2010-01-15 18:00:11 +08:00
|
|
|
# This starts subprocesses
|
2010-01-15 17:06:34 +08:00
|
|
|
run_iptestall()
|
2009-04-25 01:12:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2009-07-29 17:13:26 +08:00
|
|
|
main()
|