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

Skip to content

Commit fd17148

Browse files
committed
Rework test command for matplotlib
- specifiy parameters properly using user_options - add parameters used by travis to be passed on to nose
1 parent 42ee643 commit fd17148

File tree

3 files changed

+72
-74
lines changed

3 files changed

+72
-74
lines changed

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ env:
66
- secure: E7OCdqhZ+PlwJcn+Hd6ns9TDJgEUXiUNEI0wu7xjxB2vBRRIKtZMbuaZjd+iKDqCKuVOJKu0ClBUYxmgmpLicTwi34CfTUYt6D4uhrU+8hBBOn1iiK51cl/aBvlUUrqaRLVhukNEBGZcyqAjXSA/Qsnp2iELEmAfOUa92ZYo1sk=
77
- secure: "dfjNqGKzQG5bu3FnDNwLG8H/C4QoieFo4PfFmZPdM2RY7WIzukwKFNT6kiDfOrpwt+2bR7FhzjOGlDECGtlGOtYPN8XuXGjhcP4a4IfakdbDfF+D3NPIpf5VlE6776k0VpvcZBTMYJKNFIMc7QPkOwjvNJ2aXyfe3hBuGlKJzQU="
88
- BUILD_DOCS=false
9-
- TEST_ARGS=--no-pep8
10-
- NUMPY=numpy
9+
- TEST_ARGS=--omit-pep8
1110

1211
language: python
1312

@@ -19,7 +18,7 @@ matrix:
1918
- python: 3.3
2019
- python: 3.4
2120
- python: 2.7
22-
env: TEST_ARGS=--pep8
21+
env: TEST_ARGS=--pep8-only
2322
- python: 2.7
2423
env: BUILD_DOCS=true
2524

@@ -60,7 +59,7 @@ script:
6059
export MPL_REPO_DIR=$PWD # needed for pep8-conformance test of the examples
6160
mkdir ../tmp_test_dir
6261
cd ../tmp_test_dir
63-
gdb -return-child-result -batch -ex r -ex bt --args python ../matplotlib/tests.py -sv --processes=8 --process-timeout=300 $TEST_ARGS
62+
gdb -return-child-result -batch -ex r -ex bt --args python setup.py test --nocapture --nose-verbose --processes=8 --process-timeout=300 $TEST_ARGS
6463
else
6564
cd doc
6665
python make.py html --small --warningsaserrors

setup.py

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# This needs to be the very first thing to use distribute
99
from distribute_setup import use_setuptools
1010
use_setuptools()
11+
from setuptools.command.test import test as TestCommand
1112

1213
import sys
1314

@@ -121,20 +122,77 @@
121122
'Topic :: Scientific/Engineering :: Visualization',
122123
]
123124

124-
from setuptools.command.test import test as TestCommand
125+
125126
class NoseTestCommand(TestCommand):
127+
"""Invoke unit tests using nose after an in-place build."""
128+
129+
description = "Invoke unit tests using nose after an in-place build."
130+
user_options = [
131+
("pep8-only", None, "pep8 checks"),
132+
("omit-pep8", None, "Do not perform pep8 checks"),
133+
("nocapture", None, "do not capture stdout (nosetests)"),
134+
("nose-verbose", None, "be verbose (nosetests)"),
135+
("processes=", None, "number of processes (nosetests)"),
136+
("process-timeout=", None, "process timeout (nosetests)"),
137+
]
138+
139+
def initialize_options(self):
140+
self.pep8_only = None
141+
self.omit_pep8 = None
142+
143+
# parameters passed to nose tests
144+
self.processes = None
145+
self.process_timeout = None
146+
self.nose_verbose = None
147+
self.nocapture = None
148+
126149
def finalize_options(self):
127-
TestCommand.finalize_options(self)
128150
self.test_args = []
129-
self.test_suite = True
151+
if self.pep8_only:
152+
self.pep8_only = True
153+
if self.omit_pep8:
154+
self.omit_pep8 = True
155+
156+
if self.pep8_only and self.omit_pep8:
157+
from distutils.errors import DistutilsOptionError
158+
raise DistutilsOptionError(
159+
"You are using several options for the test command in an "
160+
"incompatible manner. Please use either one of --pep8-only,"
161+
"--omit-pep8"
162+
)
163+
164+
if self.processes:
165+
self.test_args.append("--processes={prc}".format(
166+
prc=self.processes))
167+
168+
if self.process_timeout:
169+
self.test_args.append("--process-timeout={tout}".format(
170+
tout=self.process_timeout))
171+
172+
if self.nose_verbose:
173+
self.test_args.append("--verbose")
174+
175+
if self.nocapture:
176+
self.test_args.append("--nocapture")
177+
178+
def run(self):
179+
if self.distribution.install_requires:
180+
self.distribution.fetch_build_eggs(
181+
self.distribution.install_requires)
182+
if self.distribution.tests_require:
183+
self.distribution.fetch_build_eggs(self.distribution.tests_require)
184+
185+
self.announce('running unittests with nose')
186+
self.with_project_on_sys_path(self.run_tests)
187+
130188

131189
def run_tests(self):
132190
try:
133191
import matplotlib
134192
matplotlib.use('agg')
135193
import nose
136194
from matplotlib.testing.noseclasses import KnownFailure
137-
from matplotlib import default_test_modules
195+
from matplotlib import default_test_modules as testmodules
138196
from matplotlib import font_manager
139197
import time
140198
# Make sure the font caches are created before starting any possibly
@@ -150,15 +208,14 @@ def run_tests(self):
150208
from nose.plugins import multiprocess
151209
multiprocess._instantiate_plugins = plugins
152210

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')
211+
if self.omit_pep8:
212+
testmodules.remove('matplotlib.tests.test_coding_standards')
213+
elif self.pep8_only:
214+
testmodules = ['matplotlib.tests.test_coding_standards']
215+
159216
nose.main(addplugins=[x() for x in plugins],
160-
defaultTest=default_test_modules,
161-
argv=['nosetests'],
217+
defaultTest=testmodules,
218+
argv=['nosetests'] + self.test_args,
162219
exit=False)
163220
except ImportError:
164221
sys.exit(-1)

tests.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)