Changeset 897ca7f in sasmodels
- Timestamp:
- Sep 11, 2016 11:27:52 PM (8 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:
- 7e6bea81
- Parents:
- 733a3e1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/model_test.py
r40a87fa r897ca7f 50 50 import numpy as np # type: ignore 51 51 52 from .core import list_models, load_model_info, build_model, HAVE_OPENCL 52 from . import core 53 from .core import list_models, load_model_info, build_model 53 54 from .direct_model import call_kernel, call_ER, call_VR 54 55 from .exception import annotate_exception … … 98 99 if is_py: # kernel implemented in python 99 100 test_name = "Model: %s, Kernel: python"%model_name 100 test_method_name = "test_%s_python" % model_ name101 test_method_name = "test_%s_python" % model_info.id 101 102 test = ModelTestCase(test_name, model_info, 102 103 test_method_name, … … 106 107 else: # kernel implemented in C 107 108 # test using opencl if desired and available 108 if 'opencl' in loaders and HAVE_OPENCL:109 if 'opencl' in loaders and core.HAVE_OPENCL: 109 110 test_name = "Model: %s, Kernel: OpenCL"%model_name 110 test_method_name = "test_%s_opencl" % model_ name111 test_method_name = "test_%s_opencl" % model_info.id 111 112 # Using dtype=None so that the models that are only 112 113 # correct for double precision are not tested using … … 122 123 if 'dll' in loaders: 123 124 test_name = "Model: %s, Kernel: dll"%model_name 124 test_method_name = "test_%s_dll" % model_ name125 test_method_name = "test_%s_dll" % model_info.id 125 126 test = ModelTestCase(test_name, model_info, 126 127 test_method_name, … … 249 250 return abs(target-actual)/shift < 1.5*10**-digits 250 251 251 def main(): 252 # type: () -> int 253 """ 254 Run tests given is sys.argv. 252 def run_one(model): 253 # type: (str) -> None 254 """ 255 Run the tests for a single model, printing the results to stdout. 256 257 *model* can by a python file, which is handy for checking user defined 258 plugin models. 259 """ 260 # Note that running main() directly did not work from within the 261 # wxPython pycrust console. Instead of the results appearing in the 262 # window they were printed to the underlying console. 263 from unittest.runner import TextTestResult, _WritelnDecorator 264 265 # Build a object to capture and print the test results 266 stream = _WritelnDecorator(sys.stdout) # Add writeln() method to stream 267 verbosity = 2 268 descriptions = True 269 result = TextTestResult(stream, descriptions, verbosity) 270 271 # Build a test suite containing just the model 272 loaders = ['opencl'] 273 models = [model] 274 try: 275 suite = make_suite(loaders, models) 276 except Exception: 277 import traceback 278 stream.writeln(traceback.format_exc()) 279 return 280 281 # Run the test suite 282 suite.run(result) 283 284 # Print the failures and errors 285 for _, tb in result.errors: 286 stream.writeln(tb) 287 for _, tb in result.failures: 288 stream.writeln(tb) 289 290 # Check if there are user defined tests. 291 # Yes, it is naughty to peek into the structure of the test suite, and 292 # to assume that it contains only one test. 293 if not suite._tests[0].info.tests: 294 stream.writeln("Note: %s has no user defined tests."%model) 295 296 297 def main(*models): 298 # type: (*str) -> int 299 """ 300 Run tests given is models. 255 301 256 302 Returns 0 if success or 1 if any tests fail. … … 263 309 test_args = {} 264 310 265 models = sys.argv[1:]266 311 if models and models[0] == '-v': 267 312 verbosity = 2 … … 270 315 verbosity = 1 271 316 if models and models[0] == 'opencl': 272 if not HAVE_OPENCL:317 if not core.HAVE_OPENCL: 273 318 print("opencl is not available") 274 319 return 1 … … 318 363 319 364 if __name__ == "__main__": 320 sys.exit(main( ))365 sys.exit(main(*sys.argv[1:]))
Note: See TracChangeset
for help on using the changeset viewer.