##// END OF EJS Templates
Remove unused imports in IPython.testing
Remove unused imports in IPython.testing

File last commit:

r11133:c0303633
r11133:c0303633
Show More
iptest.py
632 lines | 23.1 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
Brian Granger
Removed Twisted related things from setup scripts and testing.
r3486 calling this script (with different arguments) recursively. This
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 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.
Fernando Perez
Add module I forgot
r1574 """
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2009-2011 The IPython Development Team
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 from __future__ import print_function
Fernando Perez
Cleanup testing machinery.
r1851
Fernando Perez
Remove accidentally introduced runtime nose dependencies.
r2442 # Stdlib
MinRK
use glob for bad exclusion warning...
r7412 import glob
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 import os
import os.path as path
Fernando Perez
Improve test suite robustness by cleaning up stale processes when possible.
r2399 import signal
Fernando Perez
Add module I forgot
r1574 import sys
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 import subprocess
Fernando Perez
Make iptest more reliable under Win32....
r2111 import tempfile
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 import time
Fernando Perez
Add module I forgot
r1574 import warnings
Fernando Perez
Remove accidentally introduced runtime nose dependencies.
r2442 # 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.
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 from IPython.testing import nosepatch
Thomas Kluyver
Add assert_in method to nose for Python 2.6
r7213
# Monkeypatch extra assert methods into nose.tools if they're not already there.
# This can be dropped once we no longer test on Python 2.6
from IPython.testing import nose_assert_methods
Fernando Perez
Remove accidentally introduced runtime nose dependencies.
r2442 # Now, proceed to import nose itself
Fernando Perez
Add module I forgot
r1574 import nose.plugins.builtin
Thomas Kluyver
Monkeypatch Xunit to count known failures as skips, not errors.
r6101 from nose.plugins.xunit import Xunit
from nose import SkipTest
Fernando Perez
Cleanup testing machinery.
r1851 from nose.core import TestProgram
Fernando Perez
Add module I forgot
r1574
Fernando Perez
Remove accidentally introduced runtime nose dependencies.
r2442 # Our own imports
Jörgen Stenarson
unicode fixes
r7732 from IPython.utils import py3compat
MinRK
allow more processing in test_for...
r4857 from IPython.utils.importstring import import_item
MinRK
test for exclusions based on ipython_package_dir
r7126 from IPython.utils.path import get_ipython_module_path, get_ipython_package_dir
Thomas Kluyver
Remove unused imports in IPython.testing
r11133 from IPython.utils.process import pycmd2argv
Brian Granger
Work to address the review comments on Fernando's branch....
r2498 from IPython.utils.sysinfo import sys_info
Bradley M. Froehle
Create a unique & temporary IPYTHONDIR for each testing group.
r8038 from IPython.utils.tempdir import TemporaryDirectory
MinRK
warn on nonexistent exclusions
r7121 from IPython.utils.warn import warn
Brian Granger
Work to address the review comments on Fernando's branch....
r2498
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 from IPython.testing import globalipapp
from IPython.testing.plugin.ipdoctest import IPythonDoctest
Thomas Kluyver
Monkeypatch Xunit to count known failures as skips, not errors.
r6101 from IPython.external.decorators import KnownFailure, knownfailureif
Fernando Perez
Add module I forgot
r1574
Brian Granger
Making the doctest exclude paths os independent.
r1979 pjoin = path.join
Fernando Perez
Robustness fixes in test suite machinery....
r2494
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 # Warnings control
#-----------------------------------------------------------------------------
Brian Granger
Minor cleanup in iptest.py and growl.py.
r2512
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 # 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 )
Fernando Perez
Fixes for test suite in win32 when all dependencies (esp. Twisted) are...
r2461 # This one also comes from Twisted
warnings.filterwarnings('ignore', 'the sha module is deprecated',
DeprecationWarning)
Fernando Perez
Fixes to make test suite more robust on Fedora....
r2483 # Wx on Fedora11 spits these out
warnings.filterwarnings('ignore', 'wxPython/wxWidgets release number mismatch',
UserWarning)
Thomas Kluyver
Monkeypatch Xunit to count known failures as skips, not errors.
r6101 # ------------------------------------------------------------------------------
# Monkeypatch Xunit to count known failures as skipped.
# ------------------------------------------------------------------------------
Thomas Kluyver
Make separate function to monkeypatch Xunit.
r6102 def monkeypatch_xunit():
Thomas Kluyver
Monkeypatch Xunit to count known failures as skips, not errors.
r6101 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
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 #-----------------------------------------------------------------------------
Administrator
Fixing bugs with the testing system.
r1981 # Logic for skipping doctests
Fernando Perez
Cleanup testing machinery.
r1851 #-----------------------------------------------------------------------------
MinRK
allow more processing in test_for...
r4857 def extract_version(mod):
return mod.__version__
Fernando Perez
Cleanup testing machinery.
r1851
MinRK
allow more processing in test_for...
r4857 def test_for(item, min_version=None, callback=extract_version):
"""Test to see if item is importable, and optionally check against a minimum
version.
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
allow more processing in test_for...
r4857 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::
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
allow more processing in test_for...
r4857 In [1]: import sys
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
allow more processing in test_for...
r4857 In [2]: from IPython.testing.iptest import test_for
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
allow more processing in test_for...
r4857 In [3]: test_for('sys', (2,6), callback=lambda sys: sys.version_info)
Out[3]: True
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
allow more processing in test_for...
r4857 """
Administrator
Fixing bugs with the testing system.
r1981 try:
MinRK
allow more processing in test_for...
r4857 check = import_item(item)
Fernando Perez
Make the test suite runnable without X11 connections....
r2488 except (ImportError, RuntimeError):
MinRK
allow more processing in test_for...
r4857 # GTK reports Runtime error if it can't be initialized even if it's
Fernando Perez
Make the test suite runnable without X11 connections....
r2488 # importable.
Administrator
Fixing bugs with the testing system.
r1981 return False
else:
MinRK
add zmq checking in iptest
r3640 if min_version:
MinRK
allow more processing in test_for...
r4857 if callback:
# extra processing step to get version to compare
check = callback(check)
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
allow more processing in test_for...
r4857 return check >= min_version
MinRK
add zmq checking in iptest
r3640 else:
return True
Administrator
Fixing bugs with the testing system.
r1981
Fernando Perez
Added diagnostics printout at the end of the test suite....
r2496 # 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')
Fernando Perez
Do not generate output for empty figures in Qt console....
r3731 have['matplotlib'] = test_for('matplotlib')
Fernando Perez
Ensure that no tests are attempted if numpy or rpy2 are not present....
r7224 have['numpy'] = test_for('numpy')
MinRK
allow more processing in test_for...
r4857 have['pexpect'] = test_for('IPython.external.pexpect')
Fernando Perez
Do not generate output for empty figures in Qt console....
r3731 have['pymongo'] = test_for('pymongo')
MinRK
test for pygments before running qt tests
r6874 have['pygments'] = test_for('pygments')
MinRK
update test exclusions...
r3761 have['qt'] = test_for('IPython.external.qt')
Fernando Perez
Ensure that no tests are attempted if numpy or rpy2 are not present....
r7224 have['rpy2'] = test_for('rpy2')
MinRK
Allow IPython to run without sqlite3...
r5147 have['sqlite3'] = test_for('sqlite3')
Brian Granger
More code review changes:...
r7102 have['cython'] = test_for('Cython')
Stefan van der Walt
Skip octavemagic tests if oct2py is unavailable.
r7385 have['oct2py'] = test_for('oct2py')
MinRK
allow more processing in test_for...
r4857 have['tornado'] = test_for('tornado.version_info', (2,1,0), callback=None)
Bradley M. Froehle
Skip notebookapp testing if jinja2 is not available.
r8908 have['jinja2'] = test_for('jinja2')
Fernando Perez
Ensure that no tests are attempted if numpy or rpy2 are not present....
r7224 have['wx'] = test_for('wx')
have['wx.aui'] = test_for('wx.aui')
Brian Granger
Adding exclusion for the azure module in iptest.
r8184 have['azure'] = test_for('azure')
Brian E. Granger
Fixing test logic for nbconvert to get tests to pass.
r11095 have['sphinx'] = test_for('sphinx')
have['markdown'] = test_for('markdown')
MinRK
allow more processing in test_for...
r4857
MinRK
bump minimum pyzmq version to 2.1.11...
r9336 min_zmq = (2,1,11)
MinRK
fix callback testing for pyzmq version_info
r9339 have['zmq'] = test_for('zmq.pyzmq_version_info', min_zmq, callback=lambda x: x())
Administrator
Fixing bugs with the testing system.
r1981
Fernando Perez
Robustness fixes in test suite machinery....
r2494 #-----------------------------------------------------------------------------
# Functions and classes
#-----------------------------------------------------------------------------
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980
Fernando Perez
Added diagnostics printout at the end of the test suite....
r2496 def report():
"""Return a string with a summary report of test-related variables."""
Fernando Perez
Complete support of git commit info with IPython.sys_info()....
r3204 out = [ sys_info(), '\n']
Fernando Perez
Added diagnostics printout at the end of the test suite....
r2496
avail = []
not_avail = []
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Added diagnostics printout at the end of the test suite....
r2496 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')
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Added diagnostics printout at the end of the test suite....
r2496 return ''.join(out)
Brian Granger
Refactored iptest.py to work with new package org....
r2079 def make_exclude():
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 """Make patterns of modules and packages to exclude from testing.
Brian Granger
Minor cleanup in iptest.py and growl.py.
r2512
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 For the IPythonDoctest plugin, we need to exclude certain patterns that
cause testing problems. We should strive to minimize the number of
Brian Granger
Minor cleanup in iptest.py and growl.py.
r2512 skipped modules, since this means untested code.
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 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)
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 exclusions = [ipjoin('external'),
ipjoin('quarantine'),
ipjoin('deathrow'),
Fernando Perez
Fixes for test suite in win32 when all dependencies (esp. Twisted) are...
r2461 # This guy is probably attic material
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 ipjoin('testing', 'mkdoctests'),
Fernando Perez
Fixes for test suite in win32 when all dependencies (esp. Twisted) are...
r2461 # 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
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 ipjoin('lib', 'inputhook'),
Fernando Perez
Fix config part of the test suite.
r2417 # Config files aren't really importable stand-alone
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 ipjoin('config', 'profile'),
Fernando Perez
Skip notebook 'static' dir in test suite....
r7801 # The notebook 'static' directory contains JS, css and other
# files for web serving. Occasionally projects may put a .py
# file in there (MathJax ships a conf.py), so we might as
# well play it safe and skip the whole thing.
MinRK
update references for IPython.html
r11035 ipjoin('html', 'static'),
ipjoin('html', 'fabfile'),
Fernando Perez
Fix config part of the test suite.
r2417 ]
MinRK
Allow IPython to run without sqlite3...
r5147 if not have['sqlite3']:
exclusions.append(ipjoin('core', 'tests', 'test_history'))
exclusions.append(ipjoin('core', 'history'))
Fernando Perez
Added diagnostics printout at the end of the test suite....
r2496 if not have['wx']:
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 exclusions.append(ipjoin('lib', 'inputhookwx'))
MinRK
skip autoreload tests
r7455
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 if 'IPython.kernel.inprocess' not in sys.argv:
exclusions.append(ipjoin('kernel', 'inprocess'))
MinRK
skip autoreload tests
r7455 # FIXME: temporarily disable autoreload tests, as they can produce
# spurious failures in subsequent tests (cythonmagic).
exclusions.append(ipjoin('extensions', 'autoreload'))
exclusions.append(ipjoin('extensions', 'tests', 'test_autoreload'))
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Tweak code with suggestions from yesterday.
r3458 # 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'))
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 exclusions.append(ipjoin('kernel', 'zmq', 'gui', 'gtkembed'))
Brian Granger
Updated iptest to skip inputhook*.py files for doctesting.
r2083
Brian Granger
Refactored iptest.py to work with new package org....
r2079 # These have to be skipped on win32 because the use echo, rm, cd, etc.
Thomas Kluyver
Replace links to launchpad bugs in comments/docstrings with equivalent github links.
r3917 # See ticket https://github.com/ipython/ipython/issues/87
Brian Granger
Refactored iptest.py to work with new package org....
r2079 if sys.platform == 'win32':
Fernando Perez
Fix test suite when Twisted not available, cleanups to iptest for clarity.
r2454 exclusions.append(ipjoin('testing', 'plugin', 'test_exampleip'))
exclusions.append(ipjoin('testing', 'plugin', 'dtexample'))
Brian Granger
Refactored iptest.py to work with new package org....
r2079
Fernando Perez
Added diagnostics printout at the end of the test suite....
r2496 if not have['pexpect']:
MinRK
remove empty IPython.scripts test group
r7775 exclusions.extend([ipjoin('lib', 'irunner'),
MinRK
update iptest exclusions with recent changes
r5694 ipjoin('lib', 'tests', 'test_irunner'),
Fernando Perez
Fix imports in test suite.
r11026 ipjoin('terminal', 'console'),
MinRK
update iptest exclusions with recent changes
r5694 ])
Brian Granger
Refactored iptest.py to work with new package org....
r2079
MinRK
add zmq checking in iptest
r3640 if not have['zmq']:
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 exclusions.append(ipjoin('kernel'))
Fernando Perez
Fix imports in test suite.
r11026 exclusions.append(ipjoin('qt'))
exclusions.append(ipjoin('html'))
exclusions.append(ipjoin('consoleapp.py'))
exclusions.append(ipjoin('terminal', 'console'))
MinRK
rebase IPython.parallel after removal of IPython.kernel...
r3672 exclusions.append(ipjoin('parallel'))
MinRK
test for pygments before running qt tests
r6874 elif not have['qt'] or not have['pygments']:
Fernando Perez
Fix imports in test suite.
r11026 exclusions.append(ipjoin('qt'))
Bernardo B. Marques
remove all trailling spaces
r4872
MinRK
add pymongo to iptest exclusions
r3674 if not have['pymongo']:
exclusions.append(ipjoin('parallel', 'controller', 'mongodb'))
MinRK
various db backend fixes...
r3875 exclusions.append(ipjoin('parallel', 'tests', 'test_mongodb'))
MinRK
add zmq checking in iptest
r3640
Fernando Perez
Do not generate output for empty figures in Qt console....
r3731 if not have['matplotlib']:
Fernando Perez
Fix inline backend logic and avoid tests if mpl not available.
r5474 exclusions.extend([ipjoin('core', 'pylabtools'),
MinRK
include IPython.zmq in iptest groups
r6566 ipjoin('core', 'tests', 'test_pylabtools'),
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 ipjoin('kernel', 'zmq', 'pylab'),
MinRK
include IPython.zmq in iptest groups
r6566 ])
Fernando Perez
Do not generate output for empty figures in Qt console....
r3731
Brian Granger
More code review changes:...
r7102 if not have['cython']:
exclusions.extend([ipjoin('extensions', 'cythonmagic')])
MinRK
add missing cython exclusion in iptest
r7117 exclusions.extend([ipjoin('extensions', 'tests', 'test_cythonmagic')])
Brian Granger
More code review changes:...
r7102
Stefan van der Walt
Skip octavemagic tests if oct2py is unavailable.
r7385 if not have['oct2py']:
exclusions.extend([ipjoin('extensions', 'octavemagic')])
exclusions.extend([ipjoin('extensions', 'tests', 'test_octavemagic')])
Brian E. Granger
Check for tornado before running frontend.html tests.
r4703 if not have['tornado']:
Fernando Perez
Fix imports in test suite.
r11026 exclusions.append(ipjoin('html'))
Brian E. Granger
Check for tornado before running frontend.html tests.
r4703
Bradley M. Froehle
Skip notebookapp testing if jinja2 is not available.
r8908 if not have['jinja2']:
MinRK
update references for IPython.html
r11035 exclusions.append(ipjoin('html', 'notebookapp'))
Bradley M. Froehle
Skip notebookapp testing if jinja2 is not available.
r8908
Fernando Perez
Ensure that no tests are attempted if numpy or rpy2 are not present....
r7224 if not have['rpy2'] or not have['numpy']:
exclusions.append(ipjoin('extensions', 'rmagic'))
exclusions.append(ipjoin('extensions', 'tests', 'test_rmagic'))
Brian Granger
Adding exclusion for the azure module in iptest.
r8184 if not have['azure']:
MinRK
update references for IPython.html
r11035 exclusions.append(ipjoin('html', 'services', 'notebooks', 'azurenbmanager'))
Brian Granger
Adding exclusion for the azure module in iptest.
r8184
Brian E. Granger
Fixing test logic for nbconvert to get tests to pass.
r11095 if not all((have['pygments'], have['jinja2'], have['markdown'], have['sphinx'])):
exclusions.append(ipjoin('nbconvert'))
Brian Granger
Refactored iptest.py to work with new package org....
r2079 # This is needed for the reg-exp to match on win32 in the ipdoctest plugin.
if sys.platform == 'win32':
Fernando Perez
Massive amount of work to improve the test suite, restores doctests....
r2414 exclusions = [s.replace('\\','\\\\') for s in exclusions]
MinRK
warn on nonexistent exclusions
r7121
# check for any exclusions that don't seem to exist:
MinRK
test for exclusions based on ipython_package_dir
r7126 parent, _ = os.path.split(get_ipython_package_dir())
MinRK
warn on nonexistent exclusions
r7121 for exclusion in exclusions:
MinRK
don't warn in iptest if deathrow/quarantine are missing
r7463 if exclusion.endswith(('deathrow', 'quarantine')):
# ignore deathrow/quarantine, which exist in dev, but not install
continue
MinRK
test for exclusions based on ipython_package_dir
r7126 fullpath = pjoin(parent, exclusion)
MinRK
use glob for bad exclusion warning...
r7412 if not os.path.exists(fullpath) and not glob.glob(fullpath + '.*'):
Thomas Kluyver
Fix IPython.utils.warn API so messages are automatically displayed followed by a newline.
r8223 warn("Excluding nonexistent file: %r" % exclusion)
Brian Granger
Refactored iptest.py to work with new package org....
r2079
Fernando Perez
Massive amount of work to improve the test suite, restores doctests....
r2414 return exclusions
Administrator
Fixing doctest EXCLUDES in iptest on win32....
r1980
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 class IPTester(object):
"""Call that calls iptest or trial in a subprocess.
"""
Fernando Perez
Improve test suite robustness by cleaning up stale processes when possible.
r2399 #: 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
Bradley M. Froehle
Work around lack of os.kill in win32....
r8035 #: list, subprocesses we start (for cleanup)
processes = None
Thomas Kluyver
Produce coverage xml reports from subprocess test runners.
r5983 #: str, coverage xml output file
coverage_xml = None
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 def __init__(self, runner='iptest', params=None):
Fernando Perez
Improve test suite robustness by cleaning up stale processes when possible.
r2399 """Create new test runner."""
Fernando Perez
Robustness fixes in test suite machinery....
r2494 p = os.path
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 if runner == 'iptest':
Victor Zverovich
Use absolute path to iptest, because the tests are not always run from $IPYTHONDIR.
r11055 iptest_app = os.path.abspath(get_ipython_module_path('IPython.testing.iptest'))
Brian Granger
Removed the top-level iptest.py and INSTALLED logic....
r2507 self.runner = pycmd2argv(iptest_app) + sys.argv[1:]
Brian Granger
Minor cleanup in iptest.py and growl.py.
r2512 else:
raise Exception('Not a valid test runner: %s' % repr(runner))
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 if params is None:
params = []
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 if isinstance(params, str):
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 params = [params]
self.params = params
# Assemble call
self.call_args = self.runner+self.params
Thomas Kluyver
Pass subprocess test runners a suitable location for xunit output.
r5962
Thomas Kluyver
Use explicit for loop to find section in testing.
r5987 # Find the section we're testing (IPython.foo)
for sect in self.params:
Thomas Kluyver
Add test suite for autoreload extension...
r11073 if sect.startswith('IPython') or sect in special_test_suites: break
Thomas Kluyver
Use explicit for loop to find section in testing.
r5987 else:
raise ValueError("Section not found", self.params)
Thomas Kluyver
Pass subprocess test runners a suitable location for xunit output.
r5962 if '--with-xunit' in self.call_args:
MinRK
only add quotes around xunit-file on Windows
r7744
self.call_args.append('--xunit-file')
# FIXME: when Windows uses subprocess.call, these extra quotes are unnecessary:
xunit_file = path.abspath(sect+'.xunit.xml')
if sys.platform == 'win32':
xunit_file = '"%s"' % xunit_file
self.call_args.append(xunit_file)
Thomas Kluyver
Produce coverage xml reports from subprocess test runners.
r5983
Thomas Kluyver
Use separate option --with-xml-coverage to ask for coverage xml output.
r5985 if '--with-xml-coverage' in self.call_args:
Thomas Kluyver
Produce coverage xml reports from subprocess test runners.
r5983 self.coverage_xml = path.abspath(sect+".coverage.xml")
Thomas Kluyver
Use separate option --with-xml-coverage to ask for coverage xml output.
r5985 self.call_args.remove('--with-xml-coverage')
Thomas Kluyver
Use standard command for coverage.
r5984 self.call_args = ["coverage", "run", "--source="+sect] + self.call_args[1:]
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398
Bradley M. Froehle
Work around lack of os.kill in win32....
r8035 # Store anything we start to clean up on deletion
self.processes = []
Fernando Perez
Improve test suite robustness by cleaning up stale processes when possible.
r2399
Bradley M. Froehle
win32 iptest: Use subprocess.Popen() instead of os.system().
r7870 def _run_cmd(self):
Bradley M. Froehle
Create a unique & temporary IPYTHONDIR for each testing group.
r8038 with TemporaryDirectory() as IPYTHONDIR:
env = os.environ.copy()
env['IPYTHONDIR'] = IPYTHONDIR
# print >> sys.stderr, '*** CMD:', ' '.join(self.call_args) # dbg
subp = subprocess.Popen(self.call_args, env=env)
self.processes.append(subp)
# If this fails, the process will be left in self.processes and
# cleaned up later, but if the wait call succeeds, then we can
# clear the stored process.
retcode = subp.wait()
self.processes.pop()
return retcode
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 def run(self):
"""Run the stored commands"""
try:
Thomas Kluyver
Produce coverage xml reports from subprocess test runners.
r5983 retcode = self._run_cmd()
MinRK
allow iptest to be interrupted...
r8495 except KeyboardInterrupt:
return -signal.SIGINT
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 except:
import traceback
traceback.print_exc()
return 1 # signal failure
Thomas Kluyver
Produce coverage xml reports from subprocess test runners.
r5983
if self.coverage_xml:
Thomas Kluyver
Don't raise errors from coverage post-processing.
r5986 subprocess.call(["coverage", "xml", "-o", self.coverage_xml])
Thomas Kluyver
Produce coverage xml reports from subprocess test runners.
r5983 return retcode
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398
Fernando Perez
Improve test suite robustness by cleaning up stale processes when possible.
r2399 def __del__(self):
"""Cleanup on exit by killing any leftover processes."""
Bradley M. Froehle
Work around lack of os.kill in win32....
r8035 for subp in self.processes:
Bradley M. Froehle
Print warning message if process could not be killed.
r8036 if subp.poll() is not None:
continue # process is already dead
Fernando Perez
Improve test suite robustness by cleaning up stale processes when possible.
r2399 try:
MinRK
allow iptest to be interrupted...
r8495 print('Cleaning up stale PID: %d' % subp.pid)
Bradley M. Froehle
Work around lack of os.kill in win32....
r8035 subp.kill()
except: # (OSError, WindowsError) ?
Fernando Perez
Improve test suite robustness by cleaning up stale processes when possible.
r2399 # This is just a best effort, if we fail or the process was
# really gone, ignore it.
Bernardo B. Marques
remove all trailling spaces
r4872 pass
MinRK
allow iptest to be interrupted...
r8495 else:
for i in range(10):
if subp.poll() is None:
time.sleep(0.1)
else:
break
Fernando Perez
A few small fixes so ipythonx works, and PEP-8 cleanups I found along the way.
r2400
Bradley M. Froehle
Print warning message if process could not be killed.
r8036 if subp.poll() is None:
# The process did not die...
MinRK
allow iptest to be interrupted...
r8495 print('... failed. Manual cleanup may be required.')
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398
Thomas Kluyver
Add test suite for autoreload extension...
r11073
special_test_suites = {
'autoreload': ['IPython.extensions.autoreload', 'IPython.extensions.tests.test_autoreload'],
}
Fernando Perez
Fix imports in test suite.
r11026
Thomas Kluyver
Exclude slow tests (IPython.parallel by default in iptest
r8124 def make_runners(inc_slow=False):
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 """Define the top-level packages that need to be tested.
"""
Fernando Perez
Fixes to make test suite more robust on Fedora....
r2483 # Packages to be tested via nose, that only depend on the stdlib
Fernando Perez
Fix imports in test suite.
r11026 nose_pkg_names = ['config', 'core', 'extensions', 'lib', 'terminal',
Brian E. Granger
Fixing test logic for nbconvert to get tests to pass.
r11095 'testing', 'utils', 'nbformat']
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Fix imports in test suite.
r11026 if have['qt']:
nose_pkg_names.append('qt')
if have['tornado']:
nose_pkg_names.append('html')
MinRK
organize IPython.parallel into subpackages
r3673 if have['zmq']:
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 nose_pkg_names.append('kernel')
nose_pkg_names.append('kernel.inprocess')
Thomas Kluyver
Exclude slow tests (IPython.parallel by default in iptest
r8124 if inc_slow:
nose_pkg_names.append('parallel')
Bernardo B. Marques
remove all trailling spaces
r4872
Brian E. Granger
Fixing test logic for nbconvert to get tests to pass.
r11095 if all((have['pygments'], have['jinja2'], have['markdown'], have['sphinx'])):
nose_pkg_names.append('nbconvert')
Fernando Perez
Fixes to make test suite more robust on Fedora....
r2483 # For debugging this code, only load quick stuff
Fernando Perez
Robustness fixes in test suite machinery....
r2494 #nose_pkg_names = ['core', 'extensions'] # dbg
Fernando Perez
Fixes to make test suite more robust on Fedora....
r2483
# 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 ]
Thomas Kluyver
Add test suite for autoreload extension...
r11073
for name in special_test_suites:
runners.append((name, IPTester('iptest', params=name)))
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 return runners
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 def run_iptest():
"""Run the IPython test suite using nose.
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 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 """
Thomas Kluyver
Make separate function to monkeypatch Xunit.
r6102 # Apply our monkeypatch to Xunit
Thomas Kluyver
Only monkeypatch xunit when the tests are run using it.
r6113 if '--with-xunit' in sys.argv and not hasattr(Xunit, 'orig_addError'):
Thomas Kluyver
Make separate function to monkeypatch Xunit.
r6102 monkeypatch_xunit()
Fernando Perez
Add module I forgot
r1574
Bernardo B. Marques
remove all trailling spaces
r4872 warnings.filterwarnings('ignore',
Fernando Perez
Add module I forgot
r1574 'This will be removed soon. Use IPython.testing.util instead')
Thomas Kluyver
Add test suite for autoreload extension...
r11073
if sys.argv[1] in special_test_suites:
sys.argv[1:2] = special_test_suites[sys.argv[1]]
special_suite = True
else:
special_suite = False
Fernando Perez
Add module I forgot
r1574
Fernando Perez
Fix tests to return consistent results regardless of how they are called....
r2487 argv = sys.argv + [ '--detailed-errors', # extra info in tracebacks
Bernardo B. Marques
remove all trailling spaces
r4872
Fernando Perez
Massive amount of work to improve the test suite, restores doctests....
r2414 '--with-ipdoctest',
'--ipdoctest-tests','--ipdoctest-extension=txt',
Bernardo B. Marques
remove all trailling spaces
r4872
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',
]
MinRK
skip crash tests by default
r8201 if '-a' not in argv and '-A' not in argv:
argv = argv + ['-a', '!crash']
Fernando Perez
Add module I forgot
r1574
Fernando Perez
Robustness fixes in test suite machinery....
r2494 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')
Fernando Perez
Add module I forgot
r1574
Matthew Brett
BF - allow nose with-doctest setting in environment...
r4567 # use our plugin for doctesting. It will remove the standard doctest plugin
# if it finds it enabled
Thomas Kluyver
Add test suite for autoreload extension...
r11073 ipdt = IPythonDoctest() if special_suite else IPythonDoctest(make_exclude())
plugins = [ipdt, KnownFailure()]
Fernando Perez
Ensure that in-process test group doesn't create global IPython singleton....
r8489
# We need a global ipython running in this process, but the special
# in-process group spawns its own IPython kernels, so for *that* group we
# must avoid also opening the global one (otherwise there's a conflict of
# singletons). Ultimately the solution to this problem is to refactor our
# assumptions about what needs to be a singleton and what doesn't (app
# objects should, individual shells shouldn't). But for now, this
# workaround allows the test suite for the inprocess module to complete.
MinRK
move IPython.inprocess to IPython.kernel.inprocess
r9375 if not 'IPython.kernel.inprocess' in sys.argv:
Fernando Perez
Ensure that in-process test group doesn't create global IPython singleton....
r8489 globalipapp.start_ipython()
Fernando Perez
Massive amount of work to improve the test suite, restores doctests....
r2414 # Now nose can run
Matthew Brett
BF - allow nose with-doctest setting in environment...
r4567 TestProgram(argv=argv, addplugins=plugins)
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972
Thomas Kluyver
Exclude slow tests (IPython.parallel by default in iptest
r8124 def run_iptestall(inc_slow=False):
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 """Run the entire IPython test suite by calling nose and trial.
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 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
MinRK
remove a few more obsolete twisted notes
r6421 nose.
Thomas Kluyver
Exclude slow tests (IPython.parallel by default in iptest
r8124
Parameters
----------
inc_slow : bool, optional
Include slow tests, like IPython.parallel. By default, these tests aren't
run.
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 """
Brian Granger
Refactored iptest.py to work with new package org....
r2079
Thomas Kluyver
Exclude slow tests (IPython.parallel by default in iptest
r8124 runners = make_runners(inc_slow=inc_slow)
Brian Granger
Refactored iptest.py to work with new package org....
r2079
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 # 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.
Jörgen Stenarson
Search of getcwd and replace with getcwdu. Ignoring core/prompts.py
r4208 curdir = os.getcwdu()
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 testdir = tempfile.gettempdir()
os.chdir(testdir)
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 # Run all test runners, tracking execution time
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 failed = []
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 t_start = time.time()
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 try:
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 for (name, runner) in runners:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('*'*70)
print('IPython test group:',name)
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 res = runner.run()
if res:
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 failed.append( (name, runner) )
MinRK
allow iptest to be interrupted...
r8495 if res == -signal.SIGINT:
print("Interrupted")
break
Fernando Perez
Work in multiple places to improve state of the test suite....
r2398 finally:
os.chdir(curdir)
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 t_end = time.time()
t_tests = t_end - t_start
nrunners = len(runners)
nfail = len(failed)
# summarize results
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print()
print('*'*70)
print('Test suite completed for system with the following information:')
print(report())
print('Ran %s test groups in %.3fs' % (nrunners, t_tests))
print()
print('Status:')
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 if not failed:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('OK')
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972 else:
# If anything went wrong, point out what command to rerun manually to
# see the actual errors and individual summary
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('ERROR - %s out of %s test groups failed.' % (nfail, nrunners))
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 for name, failed_runner in failed:
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print('-'*40)
print('Runner failed:',name)
print('You may wish to rerun this one individually, with:')
Jörgen Stenarson
unicode fixes
r7732 failed_call_args = [py3compat.cast_unicode(x) for x in failed_runner.call_args]
Matthias BUSSONNIER
use print function in module with `print >>`
r7817 print(u' '.join(failed_call_args))
print()
Thomas Kluyver
Call sys.exit() at correct point in iptest.
r3895 # Ensure that our exit code indicates failure
sys.exit(1)
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972
def main():
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 for arg in sys.argv[1:]:
Thomas Kluyver
Add test suite for autoreload extension...
r11073 if arg.startswith('IPython') or arg in special_test_suites:
Fernando Perez
Make it possible to run the tests from the source dir without installation....
r2481 # This is in-process
Brian Granger
Fixing small bug in iptest. Can now be run as "iptest".
r1990 run_iptest()
Fernando Perez
Let iptest pass arguments correctly to nose (in-process or in subprocess)....
r2480 else:
Thomas Kluyver
Exclude slow tests (IPython.parallel by default in iptest
r8124 if "--all" in sys.argv:
sys.argv.remove("--all")
inc_slow = True
else:
inc_slow = False
Fernando Perez
Make it possible to run the tests from the source dir without installation....
r2481 # This starts subprocesses
Thomas Kluyver
Exclude slow tests (IPython.parallel by default in iptest
r8124 run_iptestall(inc_slow=inc_slow)
Brian Granger
Refactored iptest to include the iptestall capabilities....
r1972
if __name__ == '__main__':
Fernando Perez
Small fixes for wx-dependent tests and include clearcmd....
r2091 main()