/
__init__.py
70 lines (53 loc) · 2.02 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import (absolute_import, division, print_function,
unicode_literals)
def get_extra_test_plugins():
from .plugins.performgc import PerformGC
from .plugins.knownfailure import KnownFailure
from nose.plugins import attrib
return [PerformGC, KnownFailure, attrib.Plugin]
def get_env():
env = {'NOSE_COVER_PACKAGE': ['matplotlib', 'mpl_toolkits'],
'NOSE_COVER_HTML': 1,
'NOSE_COVER_NO_PRINT': 1}
return env
def check_deps():
try:
import nose
try:
from unittest import mock
except ImportError:
import mock
except ImportError:
print("matplotlib.test requires nose and mock to run.")
raise
def test(verbosity=None, coverage=False, switch_backend_warn=True, **kwargs):
from ... import default_test_modules, get_backend, use
old_backend = get_backend()
try:
use('agg')
import nose
from nose.plugins import multiprocess
# Nose doesn't automatically instantiate all of the plugins in the
# child processes, so we have to provide the multiprocess plugin with
# a list.
extra_plugins = get_extra_test_plugins()
multiprocess._instantiate_plugins = extra_plugins
env = get_env()
if coverage:
env['NOSE_WITH_COVERAGE'] = 1
if verbosity is not None:
env['NOSE_VERBOSE'] = verbosity
success = nose.run(
addplugins=[plugin() for plugin in extra_plugins],
env=env,
defaultTest=default_test_modules,
**kwargs
)
finally:
if old_backend.lower() != 'agg':
use(old_backend, warn=switch_backend_warn)
return success
def knownfail(msg):
from .exceptions import KnownFailureTest
# Keep the next ultra-long comment so it shows in console.
raise KnownFailureTest(msg) # An error here when running nose means that you don't have the matplotlib.testing.nose.plugins:KnownFailure plugin in use. # noqa