Changeset d92182f in sasmodels for sasmodels/model_test.py


Ignore:
Timestamp:
Mar 11, 2019 9:30:49 PM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
d8eaa3d
Parents:
aee8dfb
Message:

tweak option handling for model_test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    raee8dfb rd92182f  
    55Usage:: 
    66 
    7     python -m sasmodels.model_test [opencl|cuda|dll] model1 model2 ... 
    8  
    9     if model1 is 'all', then all except the remaining models will be tested 
     7    python -m sasmodels.model_test [opencl|cuda|dll|all] model1 model2 ... 
     8 
     9If model1 is 'all', then all except the remaining models will be tested. 
     10Subgroups are also possible, such as 'py', 'single' or '1d'.  See 
     11:func:`core.list_models` for details. 
    1012 
    1113Each model is tested using the default parameters at q=0.1, (qx, qy)=(0.1, 0.1), 
     
    9092    suite = unittest.TestSuite() 
    9193 
    92     if models[0] in core.KINDS: 
     94    try: 
     95        # See if the first model parses as a model group 
     96        group = list_models(models[0]) 
    9397        skip = models[1:] 
    94         models = list_models(models[0]) 
    95     else: 
     98        models = group 
     99    except Exception: 
    96100        skip = [] 
    97101    for model_name in models: 
     
    475479 
    476480 
    477 def main(): 
    478     # type: (*str) -> int 
    479     """ 
    480     Run tests given is models. 
    481  
    482     Returns 0 if success or 1 if any tests fail. 
    483     """ 
    484     try: 
    485         from xmlrunner import XMLTestRunner as TestRunner 
    486         test_args = {'output': 'logs'} 
    487     except ImportError: 
    488         from unittest import TextTestRunner as TestRunner 
    489         test_args = {} 
    490  
    491     parser = argparse.ArgumentParser(description="Test SasModels Models") 
    492     parser.add_argument("-v", "--verbose", action="store_const", 
    493                         default=1, const=2, help="Use verbose output") 
    494     parser.add_argument("engine", metavar="[engine]", 
    495                         help="Engines on which to run the test.  " 
    496                         "Valid values are opencl, dll, and opencl_and_dll. " 
    497                         "Defaults to opencl_and_dll if no value is given") 
    498     parser.add_argument("models", nargs="*", 
    499                         help='The names of the models to be tested.  ' 
    500                         'If the first model is "all", then all except the ' 
    501                         'remaining models will be tested.') 
    502     args, models = parser.parse_known_args() 
    503  
    504     if args.engine == "opencl": 
    505         if not use_opencl(): 
    506             print("opencl is not available") 
    507             return 1 
    508         loaders = ['opencl'] 
    509     elif args.engine == "dll": 
    510         loaders = ["dll"] 
    511     elif args.engine == "cuda": 
    512         if not use_cuda(): 
    513             print("cuda is not available") 
    514             return 1 
    515         loaders = ['cuda'] 
    516     else: 
    517         # Default to running both engines 
    518         loaders = ['dll'] 
    519         if use_opencl(): 
    520             loaders.append('opencl') 
    521         if use_cuda(): 
    522             loaders.append('cuda') 
    523         args.models.insert(0, args.engine) 
    524  
    525     runner = TestRunner(verbosity=args.verbose, **test_args) 
    526     result = runner.run(make_suite(loaders, args.models)) 
    527     return 1 if result.failures or result.errors else 0 
    528  
    529  
    530481def model_tests(): 
    531482    # type: () -> Iterator[Callable[[], None]] 
     
    562513 
    563514 
     515def main(): 
     516    # type: (*str) -> int 
     517    """ 
     518    Run tests given is models. 
     519 
     520    Returns 0 if success or 1 if any tests fail. 
     521    """ 
     522    try: 
     523        from xmlrunner import XMLTestRunner as TestRunner 
     524        test_args = {'output': 'logs'} 
     525    except ImportError: 
     526        from unittest import TextTestRunner as TestRunner 
     527        test_args = {} 
     528 
     529    parser = argparse.ArgumentParser(description="Test SasModels Models") 
     530    parser.add_argument("-v", "--verbose", action="store_const", 
     531                        default=1, const=2, help="Use verbose output") 
     532    parser.add_argument("-e", "--engine", default="all", 
     533                        help="Engines on which to run the test.  " 
     534                        "Valid values are opencl, cuda, dll, and all. " 
     535                        "Defaults to all if no value is given") 
     536    parser.add_argument("models", nargs="*", 
     537                        help="The names of the models to be tested.  " 
     538                        "If the first model is 'all', then all but the listed " 
     539                        "models will be tested.  See core.list_models() for " 
     540                        "names of other groups, such as 'py' or 'single'.") 
     541    args, models = parser.parse_known_args() 
     542 
     543    if args.engine == "opencl": 
     544        if not use_opencl(): 
     545            print("opencl is not available") 
     546            return 1 
     547        loaders = ['opencl'] 
     548    elif args.engine == "dll": 
     549        loaders = ["dll"] 
     550    elif args.engine == "cuda": 
     551        if not use_cuda(): 
     552            print("cuda is not available") 
     553            return 1 
     554        loaders = ['cuda'] 
     555    elif args.engine == "all": 
     556        loaders = ['dll'] 
     557        if use_opencl(): 
     558            loaders.append('opencl') 
     559        if use_cuda(): 
     560            loaders.append('cuda') 
     561    else: 
     562        print("unknown engine " + args.engine) 
     563        return 1 
     564 
     565    runner = TestRunner(verbosity=args.verbose, **test_args) 
     566    result = runner.run(make_suite(loaders, args.models)) 
     567    return 1 if result.failures or result.errors else 0 
     568 
     569 
    564570if __name__ == "__main__": 
    565571    sys.exit(main()) 
Note: See TracChangeset for help on using the changeset viewer.