Changeset 503527e in sasmodels


Ignore:
Timestamp:
Nov 9, 2015 4:35:43 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
bea48a6
Parents:
cbb54e2
Message:

clean up test handling for python kernels

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    r9e430d0 r503527e  
    6868        model_definition = load_model_definition(model_name) 
    6969 
    70         smoke_tests = [ 
    71             [{},0.1,None], 
    72             [{},(0.1,0.1),None], 
    73             [{},'ER',None], 
    74             [{},'VR',None], 
    75             ] 
    76         tests = smoke_tests + getattr(model_definition, 'tests', []) 
    77  
    78         if tests: # in case there are no smoke tests... 
    79             #print '------' 
    80             #print 'found tests in', model_name 
    81             #print '------' 
    82  
    83             # if ispy then use the dll loader to call pykernel 
    84             # don't try to call cl kernel since it will not be 
    85             # available in some environmentes. 
    86             ispy = callable(getattr(model_definition,'Iq', None)) 
    87  
    88             # test using opencl if desired 
    89             if not ispy and ('opencl' in loaders and HAVE_OPENCL): 
     70        #print '------' 
     71        #print 'found tests in', model_name 
     72        #print '------' 
     73 
     74        # if ispy then use the dll loader to call pykernel 
     75        # don't try to call cl kernel since it will not be 
     76        # available in some environmentes. 
     77        is_py = callable(getattr(model_definition,'Iq', None)) 
     78 
     79        if is_py:  # kernel implemented in python 
     80            test_name = "Model: %s, Kernel: python"%model_name 
     81            test_method_name = "test_%s_python" % model_name 
     82            test = ModelTestCase(test_name, model_definition, 
     83                                 test_method_name, 
     84                                 platform="dll",  # so that 
     85                                 dtype="double") 
     86            suite.addTest(test) 
     87        else:   # kernel implemented in C 
     88            # test using opencl if desired and available 
     89            if 'opencl' in loaders and HAVE_OPENCL: 
    9090                test_name = "Model: %s, Kernel: OpenCL"%model_name 
    91                 test_method = "test_%s_opencl" % model_name 
     91                test_method_name = "test_%s_opencl" % model_name 
    9292                test = ModelTestCase(test_name, model_definition, 
    93                                      tests, test_method, 
     93                                     test_method_name, 
    9494                                     platform="ocl", dtype='single') 
    9595                #print "defining", test_name 
     
    9797 
    9898            # test using dll if desired 
    99             if ispy or 'dll' in loaders: 
     99            if 'dll' in loaders: 
    100100                test_name = "Model: %s, Kernel: dll"%model_name 
    101                 test_method = "test_%s_dll" % model_name 
     101                test_method_name = "test_%s_dll" % model_name 
    102102                test = ModelTestCase(test_name, model_definition, 
    103                                      tests, test_method, 
    104                                      platform="dll", dtype="double") 
     103                                     test_method_name, 
     104                                     platform="dll", 
     105                                     dtype="double") 
    105106                suite.addTest(test) 
    106107 
     
    110111def _hide_model_case_from_nosetests(): 
    111112    class ModelTestCase(unittest.TestCase): 
    112         def __init__(self, test_name, definition, tests, test_method, 
     113        def __init__(self, test_name, definition, test_method_name, 
    113114                     platform, dtype): 
    114115            self.test_name = test_name 
    115116            self.definition = definition 
    116             self.tests = tests 
    117117            self.platform = platform 
    118118            self.dtype = dtype 
    119119 
    120             setattr(self, test_method, self._runTest) 
    121             unittest.TestCase.__init__(self, test_method) 
     120            setattr(self, test_method_name, self._runTest) 
     121            unittest.TestCase.__init__(self, test_method_name) 
    122122 
    123123        def _runTest(self): 
     124            smoke_tests = [ 
     125                [{},0.1,None], 
     126                [{},(0.1,0.1),None], 
     127                [{},'ER',None], 
     128                [{},'VR',None], 
     129                ] 
     130 
     131            tests = getattr(self.definition, 'tests', []) 
    124132            try: 
    125133                model = load_model(self.definition, dtype=self.dtype, 
    126134                                   platform=self.platform) 
    127                 for test in self.tests: 
     135                for test in smoke_tests + tests: 
    128136                    self._run_one_test(model, test) 
     137 
     138                if not tests and self.platform == "dll": 
     139                    ## Uncomment the following to make forgetting the test 
     140                    ## values an error.  Only do so for the "dll" tests 
     141                    ## to reduce noise from both opencl and dll, and because 
     142                    ## python kernels us 
     143                    raise Exception("No test cases provided") 
     144                    pass 
    129145 
    130146            except Exception,exc: 
     
    199215        loaders = ['opencl', 'dll'] 
    200216    if not models: 
    201         print >>sys.stderr, "usage: python -m sasmodels.model_test [opencl|dll|opencl_and_dll] model1 model2 ..." 
    202         print >>sys.stderr, "if model1 is 'all', then all except the remaining models will be tested" 
     217        print >>sys.stderr, """\ 
     218usage: 
     219  python -m sasmodels.model_test [opencl|dll|opencl_and_dll] model1 model2 ... 
     220 
     221If model1 is 'all', then all except the remaining models will be tested. 
     222If no compute target is specified, then models will be tested with both opencl 
     223and dll; the compute target is ignored for pure python models.""" 
     224 
    203225        return 1 
    204226 
Note: See TracChangeset for help on using the changeset viewer.