1
2
3
4
5
6
7
8
9 """Unit test interface for PyMVPA"""
10
11 import unittest
12 import numpy as np
13 from mvpa import _random_seed, cfg
14 from mvpa.base import externals, warning
15
16
18 """Runs over all tests it knows and composes a dictionary with test suite
19 instances as values and IDs as keys. IDs are the filenames of the unittest
20 without '.py' extension and 'test_' prefix.
21
22 During collection this function will run a full and verbose test for all
23 known externals.
24 """
25
26 tests = [
27
28 'test_externals',
29 'test_base',
30 'test_dochelpers',
31 'test_dataset',
32 'test_arraymapper',
33 'test_boxcarmapper',
34 'test_som',
35 'test_neighbor',
36 'test_maskeddataset',
37 'test_metadataset',
38 'test_splitter',
39 'test_state',
40 'test_params',
41 'test_eepdataset',
42
43 'test_config',
44 'test_stats',
45 'test_support',
46 'test_verbosity',
47 'test_report',
48 'test_datasetfx',
49 'test_cmdline',
50 'test_args',
51 'test_eepdataset',
52 'test_meg',
53
54 'test_kernel',
55 'test_clf',
56 'test_regr',
57 'test_knn',
58 'test_gnb',
59 'test_svm',
60 'test_plr',
61 'test_smlr',
62
63 'test_svdmapper',
64 'test_procrust',
65 'test_hyperalignment',
66 'test_samplegroupmapper',
67 'test_transformers',
68 'test_transerror',
69 'test_clfcrossval',
70 'test_searchlight',
71 'test_rfe',
72 'test_ifs',
73 'test_datameasure',
74 'test_perturbsensana',
75 'test_splitsensana',
76
77 'test_suite',
78 ]
79
80
81
82 warning('Testing for availability of external software packages. Test '
83 'cases depending on missing packages will not be part of the test '
84 'suite.')
85
86
87 warning.maxcount = 1000
88
89 externals.testAllDependencies()
90
91
92 __optional_tests = [ ('scipy', 'ridge'),
93 ('scipy', 'stats_sp'),
94 ('scipy', 'datasetfx_sp'),
95 (['lars','scipy'], 'lars'),
96 ('nifti', 'niftidataset'),
97 ('mdp', 'icamapper'),
98 ('scipy', 'zscoremapper'),
99 ('pywt', 'waveletmapper'),
100 (['cPickle', 'gzip'], 'hamster'),
101 ('nose', 'iohelpers'),
102
103 ]
104
105 if not cfg.getboolean('tests', 'lowmem', default='no'):
106 __optional_tests += [(['nifti', 'lxml'], 'atlases')]
107
108
109
110 optional_tests = []
111
112 for external, testname in __optional_tests:
113 if externals.exists(external):
114 optional_tests.append('test_%s' % testname)
115
116
117
118 tests += optional_tests
119
120
121 for t in tests:
122
123
124
125
126 exec 'import ' + t
127
128
129 return dict([(t[5:], eval(t + '.suite()')) for t in tests ])
130
131
132
133 -def run(limit=None, verbosity=None):
134 """Runs the full or a subset of the PyMVPA unittest suite.
135
136 :Parameters:
137 limit: None | list
138 If None, the full test suite is run. Alternatively, a list with test IDs
139 can be provides. IDs are the base filenames of the test implementation,
140 e.g. the ID for the suite in 'mvpa/tests/test_niftidataset.py' is
141 'niftidataset'.
142 verbosity: None | int
143 Verbosity of unittests execution. If None, controlled by PyMVPA
144 configuration tests/verbosity. Values higher than 2 enable all Python,
145 NumPy and PyMVPA warnings
146 """
147 if __debug__:
148 from mvpa.base import debug
149
150 debug.active += ['CHECK_.*']
151
152
153 suites = collectTestSuites()
154
155 if limit is None:
156
157 ts = unittest.TestSuite(suites.values())
158 else:
159 ts = unittest.TestSuite([suites[s] for s in limit])
160
161
162 class TextTestRunnerPyMVPA(unittest.TextTestRunner):
163 """Extend TextTestRunner to print out random seed which was
164 used in the case of failure"""
165 def run(self, test):
166 """Run the bloody test and puke the seed value if failed"""
167 result = super(TextTestRunnerPyMVPA, self).run(test)
168 if not result.wasSuccessful():
169 print "MVPA_SEED=%s" % _random_seed
170
171 if verbosity is None:
172 verbosity = int(cfg.get('tests', 'verbosity', default=1))
173
174 if verbosity < 3:
175
176 handler_backup = warning.handlers
177 warning.handlers = []
178
179
180 import warnings
181 warnings.simplefilter('ignore')
182
183
184 np_errsettings = np.geterr()
185 np.seterr(**dict([(x, 'ignore') for x in np_errsettings]))
186
187
188 TextTestRunnerPyMVPA(verbosity=verbosity).run(ts)
189
190 if verbosity < 3:
191
192 warning.handlers = handler_backup
193 np.seterr(**np_errsettings)
194