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_base',
28 'test_dochelpers',
29 'test_dataset',
30 'test_arraymapper',
31 'test_boxcarmapper',
32 'test_neighbor',
33 'test_maskeddataset',
34 'test_metadataset',
35 'test_splitter',
36 'test_state',
37 'test_params',
38 'test_eepdataset',
39
40 'test_config',
41 'test_stats',
42 'test_support',
43 'test_verbosity',
44 'test_iohelpers',
45 'test_datasetfx',
46 'test_cmdline',
47 'test_args',
48 'test_eepdataset',
49 'test_meg',
50
51 'test_kernel',
52 'test_clf',
53 'test_regr',
54 'test_knn',
55 'test_svm',
56 'test_plr',
57 'test_smlr',
58
59 'test_svdmapper',
60 'test_samplegroupmapper',
61 'test_transformers',
62 'test_transerror',
63 'test_clfcrossval',
64 'test_searchlight',
65 'test_rfe',
66 'test_ifs',
67 'test_datameasure',
68 'test_perturbsensana',
69 'test_splitsensana',
70
71 'test_suite',
72 ]
73
74
75
76 warning('Testing for availability of external software packages. Test '
77 'cases depending on missing packages will not be part of the test '
78 'suite.')
79
80
81 warning.maxcount = 1000
82
83 externals.testAllDependencies()
84
85
86 __optional_tests = [ ('scipy', 'ridge'),
87 ('scipy', 'datasetfx_sp'),
88 (['lars','scipy'], 'lars'),
89 ('nifti', 'niftidataset'),
90 ('mdp', 'icamapper'),
91 ('pywt', 'waveletmapper'),
92 (['cPickle', 'gzip'], 'hamster'),
93
94 ]
95
96 if not cfg.getboolean('tests', 'lowmem', default='no'):
97 __optional_tests += [(['nifti', 'lxml'], 'atlases')]
98
99
100
101 optional_tests = []
102
103 for external, testname in __optional_tests:
104 if externals.exists(external):
105 optional_tests.append('test_%s' % testname)
106
107
108
109 tests += optional_tests
110
111
112 for t in tests:
113 exec 'import ' + t
114
115
116 return dict([(t[5:], eval(t + '.suite()')) for t in tests ])
117
118
119
120 -def run(limit=None, verbosity=None):
121 """Runs the full or a subset of the PyMVPA unittest suite.
122
123 :Parameters:
124 limit: None | list
125 If None, the full test suite is run. Alternatively, a list with test IDs
126 can be provides. IDs are the base filenames of the test implementation,
127 e.g. the ID for the suite in 'mvpa/tests/test_niftidataset.py' is
128 'niftidataset'.
129 verbosity: None | int
130 Explain me
131 """
132 if __debug__:
133 from mvpa.base import debug
134
135 debug.active += ['CHECK_.*']
136
137
138 suites = collectTestSuites()
139
140 if limit is None:
141
142 ts = unittest.TestSuite(suites.values())
143 else:
144 ts = unittest.TestSuite([suites[s] for s in limit])
145
146
147 handler_backup = warning.handlers
148 warning.handlers = []
149
150
151 import warnings
152 warnings.simplefilter('ignore')
153
154 class TextTestRunnerPyMVPA(unittest.TextTestRunner):
155 """Extend TextTestRunner to print out random seed which was
156 used in the case of failure"""
157 def run(self, test):
158 """Run the bloody test and puke the seed value if failed"""
159 result = super(TextTestRunnerPyMVPA, self).run(test)
160 if not result.wasSuccessful():
161 print "MVPA_SEED=%s" % _random_seed
162
163 if verbosity is None:
164 verbosity = int(cfg.get('tests', 'verbosity', default=1))
165
166
167 TextTestRunnerPyMVPA(verbosity=verbosity).run(ts)
168
169
170 warning.handlers = handler_backup
171