Changeset 342
- Timestamp:
- 08/26/10 00:18:25
- Files:
-
- spongenet/trunk/spongenet/expand.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spongenet/trunk/spongenet/expand.py
r341 r342 5 5 6 6 > python expand.py path/to/config/file 7 8 Test for silent import. 7 > python expand.py -t 8 > python expand.py --test 9 10 Test silent import. 9 11 10 12 >>> import expand … … 22 24 import shutil 23 25 import fileinput 26 import doctest 27 import unittest 24 28 from StringIO import StringIO 25 29 26 usage = "\n".join(__doc__.splitlines()[3: 6])30 usage = "\n".join(__doc__.splitlines()[3:8]) 27 31 test_path = "tests/expand" 32 33 34 def _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 28 49 29 50 … … 98 119 try: 99 120 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.") 107 131 else: 108 132 raise IOError("Incorrect number of arguments supplied.") … … 364 388 return 365 389 366 if __name__ == "__main__": 390 391 def _main(): 392 """ 393 Run module as script. 394 395 Test silent import. 396 397 >>> from expand import _main 398 """ 399 367 400 _config_path = config_path() 368 401 if _config_path: … … 370 403 if all(_config): 371 404 expand(*_config) 405 return 406 407 if __name__ == "__main__": 408 _main()