|
121 | 121 | 'Topic :: Scientific/Engineering :: Visualization',
|
122 | 122 | ]
|
123 | 123 |
|
| 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 | + |
124 | 167 | # One doesn't normally see `if __name__ == '__main__'` blocks in a setup.py,
|
125 | 168 | # however, this is needed on Windows to avoid creating infinite subprocesses
|
126 | 169 | # when using multiprocessing.
|
|
135 | 178 | package_dir = {'': 'lib'}
|
136 | 179 | install_requires = []
|
137 | 180 | setup_requires = []
|
| 181 | + tests_require = [] |
138 | 182 | default_backend = None
|
139 | 183 |
|
140 | 184 | # Go through all of the packages and figure out which ones we are
|
|
195 | 239 | package_data[key] = list(set(val + package_data[key]))
|
196 | 240 | install_requires.extend(package.get_install_requires())
|
197 | 241 | setup_requires.extend(package.get_setup_requires())
|
| 242 | + tests_require.extend(package.get_tests_require()) |
198 | 243 |
|
199 | 244 | # Write the default matplotlibrc file
|
200 | 245 | if default_backend is None:
|
|
254 | 299 | # List third-party Python packages that we require
|
255 | 300 | install_requires=install_requires,
|
256 | 301 | setup_requires=setup_requires,
|
| 302 | + tests_require=tests_require, |
257 | 303 |
|
258 | 304 | # matplotlib has C/C++ extensions, so it's not zip safe.
|
259 | 305 | # Telling setuptools this prevents it from doing an automatic
|
260 | 306 | # check for zip safety.
|
261 | 307 | zip_safe=False,
|
| 308 | + cmdclass={'test': NoseTestCommand}, |
262 | 309 |
|
263 | 310 | **extra_args
|
264 | 311 | )
|
0 commit comments