NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

Changeset 342

Show
Ignore:
Timestamp:
08/26/10 00:18:25
Author:
cbc
Message:

Add unittest option to command line.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spongenet/trunk/spongenet/expand.py

    r341 r342  
    55 
    66   > python expand.py path/to/config/file 
    7  
    8 Test for silent import. 
     7   > python expand.py -t 
     8   > python expand.py --test 
     9 
     10Test silent import. 
    911 
    1012>>> import expand 
     
    2224import shutil 
    2325import fileinput 
     26import doctest 
     27import unittest 
    2428from StringIO import StringIO 
    2529 
    26 usage = "\n".join(__doc__.splitlines()[3:6]) 
     30usage = "\n".join(__doc__.splitlines()[3:8]) 
    2731test_path = "tests/expand" 
     32 
     33 
     34def _test(): 
     35    """ 
     36    Run doctests as unittest suite. 
     37 
     38    Test silent import 
     39 
     40    >>> from expand import _test 
     41    """ 
     42 
     43    suite = [] 
     44    suite.append(doctest.DocTestSuite()) 
     45    suite = unittest.TestSuite(suite) 
     46    unittest.TextTestRunner().run(suite) 
     47 
     48    return 
    2849 
    2950 
     
    98119    try: 
    99120        if len(sys.argv) == 2: 
    100             path = sys.argv[1] 
    101             if not os.path.exists(path): 
    102                 raise IOError(path + \ 
    103                               " does not exist.") 
    104             elif not os.path.isfile(path): 
    105                 raise IOError(path + \ 
    106                               " is not a file.") 
     121            if sys.argv[1] == "-t" or sys.argv[1] == "--test": 
     122                _test() 
     123            else: 
     124                path = sys.argv[1] 
     125                if not os.path.exists(path): 
     126                    raise IOError(path + \ 
     127                                  " does not exist.") 
     128                elif not os.path.isfile(path): 
     129                    raise IOError(path + \ 
     130                                  " is not a file.") 
    107131        else: 
    108132            raise IOError("Incorrect number of arguments supplied.") 
     
    364388    return 
    365389 
    366 if __name__ == "__main__": 
     390 
     391def _main(): 
     392    """ 
     393    Run module as script. 
     394 
     395    Test silent import. 
     396 
     397    >>> from expand import _main 
     398    """ 
     399 
    367400    _config_path = config_path() 
    368401    if _config_path: 
     
    370403        if all(_config): 
    371404            expand(*_config) 
     405    return 
     406 
     407if __name__ == "__main__": 
     408    _main()