Changeset d6adfbe in sasmodels
- Timestamp:
- Mar 3, 2015 7:07:11 PM (10 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:
- 12c810f
- Parents:
- e819f71
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
r6c2eb83 rd6adfbe 12 12 .mplconfig 13 13 /pylint_violations.txt 14 /coverage.xml 15 /.coverage -
sasmodels/model_test.py
r9890053 rd6adfbe 29 29 30 30 [ {parameters}, (qx, qy), I(qx, Iqy)], 31 [ {parameters}, [(qx1, qy1), (qx2, qy2), ...], [I(qx1,qy1), I(qx2,qy2), ...], 31 [ {parameters}, [(qx1, qy1), (qx2, qy2), ...], 32 [I(qx1,qy1), I(qx2,qy2), ...]], 32 33 33 34 [ {parameters}, 'ER', ER(pars) ], … … 80 81 def suite(loaders, models): 81 82 83 ModelTestCase = _hide_model_case_from_nosetests() 82 84 suite = unittest.TestSuite() 83 85 … … 127 129 return suite 128 130 129 class ModelTestCase(unittest.TestCase): 130 131 def __init__(self, test_name, definition, loader, tests): 132 unittest.TestCase.__init__(self) 133 134 self.test_name = test_name 135 self.definition = definition 136 self.loader = loader 137 self.tests = tests 138 139 def runTest(self): 140 #print "running", self.test_name 141 try: 142 model = self.loader(self.definition) 143 for test in self.tests: 144 pars, Q, I = test 145 146 if not isinstance(I, list): 147 I = [I] 148 if not isinstance(Q, list): 149 Q = [Q] 150 151 self.assertEqual(len(I), len(Q)) 152 153 if Q[0] == 'ER': 154 Iq = [call_ER(kernel, pars)] 155 elif Q[0] == 'VR': 156 Iq = [call_VR(kernel, pars)] 157 elif isinstance(Q[0], tuple): 158 Qx,Qy = zip(*Q) 159 Q_vectors = [np.array(Qx), np.array(Qy)] 160 kernel = make_kernel(model, Q_vectors) 161 Iq = call_kernel(kernel, pars) 162 else: 163 Q_vectors = [np.array(Q)] 164 kernel = make_kernel(model, Q_vectors) 165 Iq = call_kernel(kernel, pars) 166 167 self.assertGreater(len(Iq), 0) 168 self.assertEqual(len(I), len(Iq)) 169 170 for q, i, iq in zip(Q, I, Iq): 171 if i is None: 172 # smoke test --- make sure it runs and produces a value 173 self.assertTrue(np.isfinite(iq), 'q:%s; not finite; actual:%s' % (q, iq)) 131 def _hide_model_case_from_nosetests(): 132 class ModelTestCase(unittest.TestCase): 133 def __init__(self, test_name, definition, loader, tests): 134 unittest.TestCase.__init__(self) 135 136 self.test_name = test_name 137 self.definition = definition 138 self.loader = loader 139 self.tests = tests 140 141 def runTest(self): 142 try: 143 model = self.loader(self.definition) 144 for test in self.tests: 145 pars, Q, I = test 146 147 if not isinstance(I, list): 148 I = [I] 149 if not isinstance(Q, list): 150 Q = [Q] 151 152 self.assertEqual(len(I), len(Q)) 153 154 if Q[0] == 'ER': 155 Iq = [call_ER(kernel, pars)] 156 elif Q[0] == 'VR': 157 Iq = [call_VR(kernel, pars)] 158 elif isinstance(Q[0], tuple): 159 Qx,Qy = zip(*Q) 160 Q_vectors = [np.array(Qx), np.array(Qy)] 161 kernel = make_kernel(model, Q_vectors) 162 Iq = call_kernel(kernel, pars) 174 163 else: 175 err = abs(i - iq) 176 nrm = abs(i) 177 self.assertLess(err * 10**5, nrm, 'q:%s; expected:%s; actual:%s' % (q, i, iq)) 178 179 except Exception,exc: 180 annotate_exception(exc, self.test_name) 181 raise 164 Q_vectors = [np.array(Q)] 165 kernel = make_kernel(model, Q_vectors) 166 Iq = call_kernel(kernel, pars) 167 168 self.assertGreater(len(Iq), 0) 169 self.assertEqual(len(I), len(Iq)) 170 171 for q, i, iq in zip(Q, I, Iq): 172 if i is None: 173 # smoke test --- make sure it runs and produces a value 174 self.assertTrue(np.isfinite(iq), 'q:%s; not finite; actual:%s' % (q, iq)) 175 else: 176 err = abs(i - iq) 177 nrm = abs(i) 178 self.assertLess(err * 10**5, nrm, 'q:%s; expected:%s; actual:%s' % (q, i, iq)) 179 180 except Exception,exc: 181 annotate_exception(exc, self.test_name) 182 raise 183 184 return ModelTestCase 185 186 187 # let nosetests sniff out the tests 188 def model_tests(): 189 tests = suite(['opencl','dll'],['all']) 190 for test_i in tests: 191 yield test_i.runTest 182 192 183 193 def main(): 184 185 194 models = sys.argv[1:] 186 195 if models and models[0] == 'opencl': 187 196 if load_model_cl is None: 188 197 print >>sys.stderr, "opencl is not available" 189 sys.exit(1)198 return 1 190 199 loaders = ['opencl'] 191 200 models = models[1:] … … 197 206 if load_model_cl is None: 198 207 print >>sys.stderr, "opencl is not available" 199 sys.exit(1)208 return 1 200 209 loaders = ['opencl', 'dll'] 201 210 models = models[1:] 202 211 else: 203 212 loaders = ['opencl', 'dll'] 204 if models: 205 runner = unittest.TextTestRunner() 206 runner.run(suite(loaders, models)) 207 else: 213 if not models: 208 214 print >>sys.stderr, "usage: python -m sasmodels.model_test [opencl|dll|opencl_and_dll] model1 model2 ..." 209 215 print >>sys.stderr, "if model1 is 'all', then all except the remaining models will be tested" 216 return 1 217 218 #run_tests(loaders, models) 219 runner = unittest.TextTestRunner() 220 result = runner.run(suite(loaders, models)) 221 return 1 if result.failures or result.errors else 0 210 222 211 223 if __name__ == "__main__": 212 main()224 sys.exit(main())
Note: See TracChangeset
for help on using the changeset viewer.