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

Source Code for Package mvpa.tests

  1  #emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- 
  2  #ex: set 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_neighbor', 33 'test_maskeddataset', 34 'test_metadataset', 35 'test_splitter', 36 'test_state', 37 'test_params', 38 'test_eepdataset', 39 # Misc supporting utilities 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 # Classifiers (longer tests) 51 'test_kernel', 52 'test_clf', 53 'test_regr', 54 'test_knn', 55 'test_svm', 56 'test_plr', 57 'test_smlr', 58 # Various algorithms 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 # And the suite (all-in-1) 71 'test_suite', 72 ] 73 74 # provide people with a hint about the warnings that might show up in a 75 # second 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 # So we could see all warnings about missing dependencies 81 warning.maxcount = 1000 82 # fully test of externals 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 # ('mdp', 'pcamapper'), 94 ] 95 96 if not cfg.getboolean('tests', 'lowmem', default='no'): 97 __optional_tests += [(['nifti', 'lxml'], 'atlases')] 98 99 100 # and now for the optional tests 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 # finally merge all of them 109 tests += optional_tests 110 111 # import all test modules 112 for t in tests: 113 exec 'import ' + t 114 115 # instanciate all tests suites and return dict of them (with ID as key) 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 # Lets add some targets which provide additional testing 135 debug.active += ['CHECK_.*'] 136 137 # collect all tests 138 suites = collectTestSuites() 139 140 if limit is None: 141 # make global test suite (use them all) 142 ts = unittest.TestSuite(suites.values()) 143 else: 144 ts = unittest.TestSuite([suites[s] for s in limit]) 145 146 # no MVPA warnings during whole testsuite (but restore handlers later on) 147 handler_backup = warning.handlers 148 warning.handlers = [] 149 150 # No python warnings (like ctypes version for slmr) 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 # finally run it 167 TextTestRunnerPyMVPA(verbosity=verbosity).run(ts) 168 169 # restore warning handlers 170 warning.handlers = handler_backup 171