Index: spongenet/trunk/spongenet/expand.py =================================================================== --- spongenet/trunk/spongenet/expand.py (revision 341) +++ spongenet/trunk/spongenet/expand.py (revision 342) @@ -5,6 +5,8 @@ > python expand.py path/to/config/file - -Test for silent import. + > python expand.py -t + > python expand.py --test + +Test silent import. >>> import expand @@ -22,8 +24,27 @@ import shutil import fileinput +import doctest +import unittest from StringIO import StringIO -usage = "\n".join(__doc__.splitlines()[3:6]) +usage = "\n".join(__doc__.splitlines()[3:8]) test_path = "tests/expand" + + +def _test(): + """ + Run doctests as unittest suite. + + Test silent import + + >>> from expand import _test + """ + + suite = [] + suite.append(doctest.DocTestSuite()) + suite = unittest.TestSuite(suite) + unittest.TextTestRunner().run(suite) + + return @@ -98,11 +119,14 @@ try: if len(sys.argv) == 2: - path = sys.argv[1] - if not os.path.exists(path): - raise IOError(path + \ - " does not exist.") - elif not os.path.isfile(path): - raise IOError(path + \ - " is not a file.") + if sys.argv[1] == "-t" or sys.argv[1] == "--test": + _test() + else: + path = sys.argv[1] + if not os.path.exists(path): + raise IOError(path + \ + " does not exist.") + elif not os.path.isfile(path): + raise IOError(path + \ + " is not a file.") else: raise IOError("Incorrect number of arguments supplied.") @@ -364,5 +388,14 @@ return -if __name__ == "__main__": + +def _main(): + """ + Run module as script. + + Test silent import. + + >>> from expand import _main + """ + _config_path = config_path() if _config_path: @@ -370,2 +403,6 @@ if all(_config): expand(*_config) + return + +if __name__ == "__main__": + _main()