Changes in / [aee8dfb:259b116] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/model_test.py

    r00afc15 r00afc15  
    4545from __future__ import print_function 
    4646 
    47 import argparse 
    4847import sys 
    4948import unittest 
     
    475474 
    476475 
    477 def main(): 
     476def main(*models): 
    478477    # type: (*str) -> int 
    479478    """ 
     
    489488        test_args = {} 
    490489 
    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": 
     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': 
    505496        if not use_opencl(): 
    506497            print("opencl is not available") 
    507498            return 1 
    508499        loaders = ['opencl'] 
    509     elif args.engine == "dll": 
    510         loaders = ["dll"] 
    511     elif args.engine == "cuda": 
     500        models = models[1:] 
     501    elif models and models[0] == 'cuda': 
    512502        if not use_cuda(): 
    513503            print("cuda is not available") 
    514504            return 1 
    515505        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:] 
    516511    else: 
    517         # Default to running both engines 
    518512        loaders = ['dll'] 
    519513        if use_opencl(): 
     
    521515        if use_cuda(): 
    522516            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)) 
     517    if not models: 
     518        print("""\ 
     519usage: 
     520  python -m sasmodels.model_test [-v] [opencl|cuda|dll] model1 model2 ... 
     521 
     522If -v is included on the command line, then use verbose output. 
     523 
     524If no platform is specified, then models will be tested with dll, and 
     525if available, OpenCL and CUDA; the compute target is ignored for pure python models. 
     526 
     527If 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)) 
    527535    return 1 if result.failures or result.errors else 0 
    528536 
     
    563571 
    564572if __name__ == "__main__": 
    565     sys.exit(main()) 
     573    sys.exit(main(*sys.argv[1:])) 
Note: See TracChangeset for help on using the changeset viewer.