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