Package mvpa :: Package tests
[hide private]
[frames] | no frames]

Source Code for Package mvpa.tests

  1  # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- 
  2  # vi: set ft=python sts=4 ts=4 sw=4 et: 
  3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ## 
  4  # 
  5  #   See COPYING file distributed along with the PyMVPA package for the 
  6  #   copyright and license terms. 
  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   
16 -def collectTestSuites():
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 # list all test modules (without .py extension) 25 tests = [ 26 # Basic data structures/manipulators 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 # Misc supporting utilities 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 # Classifiers (longer tests) 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 # Various algorithms 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 # And the suite (all-in-1) 77 'test_suite', 78 ] 79 80 # provide people with a hint about the warnings that might show up in a 81 # second 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 # So we could see all warnings about missing dependencies 87 warning.maxcount = 1000 88 # fully test of externals 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 # ('mdp', 'pcamapper'), 102 ] 103 104 if not cfg.getboolean('tests', 'lowmem', default='no'): 105 __optional_tests += [(['nifti', 'lxml'], 'atlases')] 106 107 108 # and now for the optional tests 109 optional_tests = [] 110 111 for external, testname in __optional_tests: 112 if externals.exists(external): 113 optional_tests.append('test_%s' % testname) 114 115 116 # finally merge all of them 117 tests += optional_tests 118 119 # import all test modules 120 for t in tests: 121 exec 'import ' + t 122 123 # instanciate all tests suites and return dict of them (with ID as key) 124 return dict([(t[5:], eval(t + '.suite()')) for t in tests ])
125 126 127
128 -def run(limit=None, verbosity=None):
129 """Runs the full or a subset of the PyMVPA unittest suite. 130 131 :Parameters: 132 limit: None | list 133 If None, the full test suite is run. Alternatively, a list with test IDs 134 can be provides. IDs are the base filenames of the test implementation, 135 e.g. the ID for the suite in 'mvpa/tests/test_niftidataset.py' is 136 'niftidataset'. 137 verbosity: None | int 138 Verbosity of unittests execution. If None, controlled by PyMVPA 139 configuration tests/verbosity 140 """ 141 if __debug__: 142 from mvpa.base import debug 143 # Lets add some targets which provide additional testing 144 debug.active += ['CHECK_.*'] 145 146 # collect all tests 147 suites = collectTestSuites() 148 149 if limit is None: 150 # make global test suite (use them all) 151 ts = unittest.TestSuite(suites.values()) 152 else: 153 ts = unittest.TestSuite([suites[s] for s in limit]) 154 155 # no MVPA warnings during whole testsuite (but restore handlers later on) 156 handler_backup = warning.handlers 157 warning.handlers = [] 158 159 # No python warnings (like ctypes version for slmr) 160 import warnings 161 warnings.simplefilter('ignore') 162 163 class TextTestRunnerPyMVPA(unittest.TextTestRunner): 164 """Extend TextTestRunner to print out random seed which was 165 used in the case of failure""" 166 def run(self, test): 167 """Run the bloody test and puke the seed value if failed""" 168 result = super(TextTestRunnerPyMVPA, self).run(test) 169 if not result.wasSuccessful(): 170 print "MVPA_SEED=%s" % _random_seed
171 172 if verbosity is None: 173 verbosity = int(cfg.get('tests', 'verbosity', default=1)) 174 175 # finally run it 176 TextTestRunnerPyMVPA(verbosity=verbosity).run(ts) 177 178 # restore warning handlers 179 warning.handlers = handler_backup 180