8
8
# This needs to be the very first thing to use distribute
9
9
from distribute_setup import use_setuptools
10
10
use_setuptools ()
11
+ from setuptools .command .test import test as TestCommand
11
12
12
13
import sys
13
14
121
122
'Topic :: Scientific/Engineering :: Visualization' ,
122
123
]
123
124
124
- from setuptools . command . test import test as TestCommand
125
+
125
126
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
+
126
149
def finalize_options (self ):
127
- TestCommand .finalize_options (self )
128
150
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
+
130
188
131
189
def run_tests (self ):
132
190
try :
133
191
import matplotlib
134
192
matplotlib .use ('agg' )
135
193
import nose
136
194
from matplotlib .testing .noseclasses import KnownFailure
137
- from matplotlib import default_test_modules
195
+ from matplotlib import default_test_modules as testmodules
138
196
from matplotlib import font_manager
139
197
import time
140
198
# Make sure the font caches are created before starting any possibly
@@ -150,15 +208,14 @@ def run_tests(self):
150
208
from nose .plugins import multiprocess
151
209
multiprocess ._instantiate_plugins = plugins
152
210
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
+
159
216
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 ,
162
219
exit = False )
163
220
except ImportError :
164
221
sys .exit (- 1 )
0 commit comments