Skip to content

Commit

Permalink
Merge pull request #5330 from mdboom/reduce-testing-duplication
Browse files Browse the repository at this point in the history
TST: Reduce dupe between tests.py and matplotlib.test
  • Loading branch information
tacaswell committed Oct 28, 2015
2 parents b9957b1 + a4715f9 commit 0b4a897
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 40 deletions.
9 changes: 1 addition & 8 deletions .travis.yml
Expand Up @@ -62,21 +62,14 @@ install:
pip install --upgrade setuptools
# Install only from travis wheelhouse
- if [ -z "$PRE" ]; then
wheelhouse_pip_install python-dateutil $NUMPY $PANDAS pyparsing pillow sphinx!=1.3.0;
wheelhouse_pip_install python-dateutil $NUMPY $PANDAS pyparsing pillow sphinx!=1.3.0 $MOCK;
else
pip install $PRE python-dateutil $NUMPY pyparsing pillow sphinx!=1.3.0;
fi
# Always install from pypi
- pip install $PRE pep8 cycler
- 'pip install https://github.com/tacaswell/nose/zipball/mnt_py36_compat#egg=nose'

# Install mock on python 2. Python 2.6 requires mock 1.0.1
# Since later versions have dropped support
- |
if [[ -n "$MOCK" ]]; then
echo $MOCK
pip install $MOCK
fi;
# We manually install humor sans using the package from Ubuntu 14.10. Unfortunatly humor sans is not
# availible in the Ubuntu version used by Travis but we can manually install the deb from a later
# version since is it basically just a .ttf file
Expand Down
32 changes: 19 additions & 13 deletions lib/matplotlib/__init__.py
Expand Up @@ -1487,7 +1487,14 @@ def tk_window_focus():
]


def verify_test_dependencies():
def _init_tests():
try:
import faulthandler
except ImportError:
pass
else:
faulthandler.enable()

if not os.path.isdir(os.path.join(os.path.dirname(__file__), 'tests')):
raise ImportError("matplotlib test data is not installed")

Expand All @@ -1502,37 +1509,36 @@ def verify_test_dependencies():
raise


def _get_extra_test_plugins():
from .testing.noseclasses import KnownFailure
from nose.plugins import attrib

return [KnownFailure, attrib.Plugin]


def test(verbosity=1):
"""run the matplotlib test suite"""
verify_test_dependencies()
try:
import faulthandler
except ImportError:
pass
else:
faulthandler.enable()
_init_tests()

old_backend = rcParams['backend']
try:
use('agg')
import nose
import nose.plugins.builtin
from .testing.noseclasses import KnownFailure
from nose.plugins.manager import PluginManager
from nose.plugins import multiprocess

# store the old values before overriding
plugins = []
plugins.append(KnownFailure())
plugins = _get_extra_test_plugins()
plugins.extend([plugin() for plugin in nose.plugins.builtin.plugins])

manager = PluginManager(plugins=plugins)
manager = PluginManager(plugins=[x() for x in plugins])
config = nose.config.Config(verbosity=verbosity, plugins=manager)

# Nose doesn't automatically instantiate all of the plugins in the
# child processes, so we have to provide the multiprocess plugin with
# a list.
multiprocess._instantiate_plugins = [KnownFailure]
multiprocess._instantiate_plugins = plugins

success = nose.run(
defaultTest=default_test_modules,
Expand Down
27 changes: 8 additions & 19 deletions tests.py
Expand Up @@ -17,30 +17,19 @@
matplotlib.use('agg')

import nose
from nose.plugins import attrib
from matplotlib.testing.noseclasses import KnownFailure
from matplotlib import default_test_modules

plugins = [KnownFailure, attrib.Plugin]

# Nose doesn't automatically instantiate all of the plugins in the
# child processes, so we have to provide the multiprocess plugin with
# a list.
from nose.plugins import multiprocess
multiprocess._instantiate_plugins = plugins


def run(extra_args):
try:
import faulthandler
except ImportError:
pass
else:
faulthandler.enable()
from nose.plugins import multiprocess

matplotlib._init_tests()

if not os.path.isdir(
os.path.join(os.path.dirname(matplotlib.__file__), 'tests')):
raise ImportError("matplotlib test data is not installed")
# Nose doesn't automatically instantiate all of the plugins in the
# child processes, so we have to provide the multiprocess plugin with
# a list.
plugins = matplotlib._get_extra_test_plugins()
multiprocess._instantiate_plugins = plugins

nose.main(addplugins=[x() for x in plugins],
defaultTest=default_test_modules,
Expand Down

0 comments on commit 0b4a897

Please sign in to comment.