Changeset aa4946b in sasmodels for sasmodels/model_test.py


Ignore:
Timestamp:
Mar 11, 2015 11:15:40 PM (9 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:
af1d68c
Parents:
49d1d42f
Message:

refactor so kernels are loaded via core.load_model

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    ra217f7d raa4946b  
    5050import numpy as np 
    5151 
    52 from .core import list_models, load_model_definition 
    53 from .core import load_model_cl, load_model_dll 
     52from .core import list_models, load_model_definition, load_model, HAVE_OPENCL 
    5453from .core import make_kernel, call_kernel, call_ER, call_VR 
     54 
    5555 
    5656def annotate_exception(exc, msg): 
     
    8080            exc.args = (" ".join((str(exc),msg)),) 
    8181 
     82 
    8283def make_suite(loaders, models): 
    8384 
     
    113114 
    114115            # test using opencl if desired 
    115             if not ispy and ('opencl' in loaders and load_model_cl): 
     116            if not ispy and ('opencl' in loaders and HAVE_OPENCL): 
    116117                test_name = "Model: %s, Kernel: OpenCL"%model_name 
    117118                test_method = "test_%s_opencl" % model_name 
    118119                test = ModelTestCase(test_name, model_definition, 
    119                                      load_model_cl, tests, test_method) 
     120                                     tests, test_method, 
     121                                     platform="ocl", dtype='single') 
    120122                #print "defining", test_name 
    121123                suite.addTest(test) 
    122124 
    123125            # test using dll if desired 
    124             if ispy or ('dll' in loaders and load_model_dll): 
     126            if ispy or 'dll' in loaders: 
    125127                test_name = "Model: %s, Kernel: dll"%model_name 
    126128                test_method = "test_%s_dll" % model_name 
    127129                test = ModelTestCase(test_name, model_definition, 
    128                                      load_model_dll, tests, test_method) 
     130                                     tests, test_method, 
     131                                     platform="dll", dtype="double") 
    129132                suite.addTest(test) 
    130133 
    131134    return suite 
     135 
    132136 
    133137def _hide_model_case_from_nosetests(): 
    134138    class ModelTestCase(unittest.TestCase): 
    135         def __init__(self, test_name, definition, loader, tests, test_method): 
     139        def __init__(self, test_name, definition, tests, test_method, 
     140                     platform, dtype): 
    136141            self.test_name = test_name 
    137142            self.definition = definition 
    138             self.loader = loader 
    139143            self.tests = tests 
     144            self.platform = platform 
     145            self.dtype = dtype 
    140146 
    141147            setattr(self, test_method, self._runTest) 
     
    144150        def _runTest(self): 
    145151            try: 
    146                 model = self.loader(self.definition) 
     152                model = load_model(self.definition, dtype=self.dtype, 
     153                                   platform=self.platform) 
    147154                for test in self.tests: 
    148155                    self._run_one_test(model, test) 
     
    195202 
    196203def main(): 
     204    """ 
     205    Run tests given is sys.argv. 
     206 
     207    Returns 0 if success or 1 if any tests fail. 
     208    """ 
    197209    models = sys.argv[1:] 
    198210    if models and models[0] == 'opencl': 
    199         if load_model_cl is None: 
     211        if not HAVE_OPENCL: 
    200212            print >>sys.stderr, "opencl is not available" 
    201213            return 1 
     
    207219        models = models[1:] 
    208220    elif models and models[0] == 'opencl_and_dll': 
    209         if load_model_cl is None: 
    210             print >>sys.stderr, "opencl is not available" 
    211             return 1 
    212221        loaders = ['opencl', 'dll'] 
    213222        models = models[1:] 
     
    225234 
    226235 
    227 # let nosetests sniff out the tests 
    228236def model_tests(): 
     237    """ 
     238    Test runner visible to nosetests. 
     239 
     240    Run "nosetests sasmodels" on the command line to invoke it. 
     241    """ 
    229242    tests = make_suite(['opencl','dll'],['all']) 
    230243    for test_i in tests: 
    231244        yield test_i._runTest 
    232245 
     246 
    233247if __name__ == "__main__": 
    234248    sys.exit(main()) 
Note: See TracChangeset for help on using the changeset viewer.