Changeset aa4946b in sasmodels for sasmodels/model_test.py
- Timestamp:
- Mar 11, 2015 11:15:40 PM (9 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/model_test.py
ra217f7d raa4946b 50 50 import numpy as np 51 51 52 from .core import list_models, load_model_definition 53 from .core import load_model_cl, load_model_dll 52 from .core import list_models, load_model_definition, load_model, HAVE_OPENCL 54 53 from .core import make_kernel, call_kernel, call_ER, call_VR 54 55 55 56 56 def annotate_exception(exc, msg): … … 80 80 exc.args = (" ".join((str(exc),msg)),) 81 81 82 82 83 def make_suite(loaders, models): 83 84 … … 113 114 114 115 # 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): 116 117 test_name = "Model: %s, Kernel: OpenCL"%model_name 117 118 test_method = "test_%s_opencl" % model_name 118 119 test = ModelTestCase(test_name, model_definition, 119 load_model_cl, tests, test_method) 120 tests, test_method, 121 platform="ocl", dtype='single') 120 122 #print "defining", test_name 121 123 suite.addTest(test) 122 124 123 125 # test using dll if desired 124 if ispy or ('dll' in loaders and load_model_dll):126 if ispy or 'dll' in loaders: 125 127 test_name = "Model: %s, Kernel: dll"%model_name 126 128 test_method = "test_%s_dll" % model_name 127 129 test = ModelTestCase(test_name, model_definition, 128 load_model_dll, tests, test_method) 130 tests, test_method, 131 platform="dll", dtype="double") 129 132 suite.addTest(test) 130 133 131 134 return suite 135 132 136 133 137 def _hide_model_case_from_nosetests(): 134 138 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): 136 141 self.test_name = test_name 137 142 self.definition = definition 138 self.loader = loader139 143 self.tests = tests 144 self.platform = platform 145 self.dtype = dtype 140 146 141 147 setattr(self, test_method, self._runTest) … … 144 150 def _runTest(self): 145 151 try: 146 model = self.loader(self.definition) 152 model = load_model(self.definition, dtype=self.dtype, 153 platform=self.platform) 147 154 for test in self.tests: 148 155 self._run_one_test(model, test) … … 195 202 196 203 def main(): 204 """ 205 Run tests given is sys.argv. 206 207 Returns 0 if success or 1 if any tests fail. 208 """ 197 209 models = sys.argv[1:] 198 210 if models and models[0] == 'opencl': 199 if load_model_cl is None:211 if not HAVE_OPENCL: 200 212 print >>sys.stderr, "opencl is not available" 201 213 return 1 … … 207 219 models = models[1:] 208 220 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 1212 221 loaders = ['opencl', 'dll'] 213 222 models = models[1:] … … 225 234 226 235 227 # let nosetests sniff out the tests228 236 def model_tests(): 237 """ 238 Test runner visible to nosetests. 239 240 Run "nosetests sasmodels" on the command line to invoke it. 241 """ 229 242 tests = make_suite(['opencl','dll'],['all']) 230 243 for test_i in tests: 231 244 yield test_i._runTest 232 245 246 233 247 if __name__ == "__main__": 234 248 sys.exit(main())
Note: See TracChangeset
for help on using the changeset viewer.