Changes in / [259b116:aee8dfb] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    r00afc15 r00afc15  
    4545from __future__ import print_function 
    4646 
     47import argparse 
    4748import sys 
    4849import unittest 
     
    474475 
    475476 
    476 def main(*models): 
     477def main(): 
    477478    # type: (*str) -> int 
    478479    """ 
     
    488489        test_args = {} 
    489490 
    490     if models and models[0] == '-v': 
    491         verbosity = 2 
    492         models = models[1:] 
    493     else: 
    494         verbosity = 1 
    495     if models and models[0] == 'opencl': 
     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": 
    496505        if not use_opencl(): 
    497506            print("opencl is not available") 
    498507            return 1 
    499508        loaders = ['opencl'] 
    500         models = models[1:] 
    501     elif models and models[0] == 'cuda': 
     509    elif args.engine == "dll": 
     510        loaders = ["dll"] 
     511    elif args.engine == "cuda": 
    502512        if not use_cuda(): 
    503513            print("cuda is not available") 
    504514            return 1 
    505515        loaders = ['cuda'] 
    506         models = models[1:] 
    507     elif models and models[0] == 'dll': 
    508         # TODO: test if compiler is available? 
    509         loaders = ['dll'] 
    510         models = models[1:] 
    511516    else: 
     517        # Default to running both engines 
    512518        loaders = ['dll'] 
    513519        if use_opencl(): 
     
    515521        if use_cuda(): 
    516522            loaders.append('cuda') 
    517     if not models: 
    518         print("""\ 
    519 usage: 
    520   python -m sasmodels.model_test [-v] [opencl|cuda|dll] model1 model2 ... 
    521  
    522 If -v is included on the command line, then use verbose output. 
    523  
    524 If no platform is specified, then models will be tested with dll, and 
    525 if available, OpenCL and CUDA; the compute target is ignored for pure python models. 
    526  
    527 If model1 is 'all', then all except the remaining models will be tested. 
    528  
    529 """) 
    530  
    531         return 1 
    532  
    533     runner = TestRunner(verbosity=verbosity, **test_args) 
    534     result = runner.run(make_suite(loaders, models)) 
     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)) 
    535527    return 1 if result.failures or result.errors else 0 
    536528 
     
    571563 
    572564if __name__ == "__main__": 
    573     sys.exit(main(*sys.argv[1:])) 
     565    sys.exit(main()) 
Note: See TracChangeset for help on using the changeset viewer.