Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ab2392

Browse files
committed
Nose and Mock as tests_require deps, test command
- require nose and mock for tests, not for normal installation - implement a test command in setup.py for invoking tests
1 parent 2077a46 commit 6ab2392

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

setup.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,49 @@
121121
'Topic :: Scientific/Engineering :: Visualization',
122122
]
123123

124+
from setuptools.command.test import test as TestCommand
125+
class NoseTestCommand(TestCommand):
126+
def finalize_options(self):
127+
TestCommand.finalize_options(self)
128+
self.test_args = []
129+
self.test_suite = True
130+
131+
def run_tests(self):
132+
try:
133+
import matplotlib
134+
matplotlib.use('agg')
135+
import nose
136+
from matplotlib.testing.noseclasses import KnownFailure
137+
from matplotlib import default_test_modules
138+
from matplotlib import font_manager
139+
import time
140+
# Make sure the font caches are created before starting any possibly
141+
# parallel tests
142+
if font_manager._fmcache is not None:
143+
while not os.path.exists(font_manager._fmcache):
144+
time.sleep(0.5)
145+
plugins = [KnownFailure]
146+
147+
# Nose doesn't automatically instantiate all of the plugins in the
148+
# child processes, so we have to provide the multiprocess plugin
149+
# with a list.
150+
from nose.plugins import multiprocess
151+
multiprocess._instantiate_plugins = plugins
152+
153+
if '--no-pep8' in sys.argv:
154+
default_test_modules.remove('matplotlib.tests.test_coding_standards')
155+
sys.argv.remove('--no-pep8')
156+
elif '--pep8' in sys.argv:
157+
default_test_modules = ['matplotlib.tests.test_coding_standards']
158+
sys.argv.remove('--pep8')
159+
nose.main(addplugins=[x() for x in plugins],
160+
defaultTest=default_test_modules,
161+
argv=['nosetests'],
162+
exit=False)
163+
except ImportError:
164+
sys.exit(-1)
165+
166+
124167
# One doesn't normally see `if __name__ == '__main__'` blocks in a setup.py,
125168
# however, this is needed on Windows to avoid creating infinite subprocesses
126169
# when using multiprocessing.
@@ -135,6 +178,7 @@
135178
package_dir = {'': 'lib'}
136179
install_requires = []
137180
setup_requires = []
181+
tests_require = []
138182
default_backend = None
139183

140184
# Go through all of the packages and figure out which ones we are
@@ -195,6 +239,7 @@
195239
package_data[key] = list(set(val + package_data[key]))
196240
install_requires.extend(package.get_install_requires())
197241
setup_requires.extend(package.get_setup_requires())
242+
tests_require.extend(package.get_tests_require())
198243

199244
# Write the default matplotlibrc file
200245
if default_backend is None:
@@ -254,11 +299,13 @@
254299
# List third-party Python packages that we require
255300
install_requires=install_requires,
256301
setup_requires=setup_requires,
302+
tests_require=tests_require,
257303

258304
# matplotlib has C/C++ extensions, so it's not zip safe.
259305
# Telling setuptools this prevents it from doing an automatic
260306
# check for zip safety.
261307
zip_safe=False,
308+
cmdclass={'test': NoseTestCommand},
262309

263310
**extra_args
264311
)

setupext.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ def get_setup_requires(self):
415415
"""
416416
return []
417417

418+
def get_tests_require(self):
419+
"""
420+
Get a list of Python packages that we require for executing tests.
421+
"""
422+
return []
423+
418424
def _check_for_pkg_config(self, package, include_file, min_version=None,
419425
version=None):
420426
"""
@@ -692,7 +698,7 @@ def get_package_data(self):
692698
'sphinxext/tests/tinypages/_static/*',
693699
]}
694700

695-
def get_install_requires(self):
701+
def get_tests_require(self):
696702
requires = ['nose>=%s' % self.nose_min_version]
697703
if not sys.version_info >= (3, 3):
698704
requires += ['mock']

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ commands =
1313
{envpython} {toxinidir}/tests.py --processes=-1 --process-timeout=300
1414
deps =
1515
nose
16+
mock
1617
numpy

0 commit comments

Comments
 (0)