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