def test_suite(): return tests.test_suite()
def test_suite(): import tests return tests.test_suite()
def main(): runner = unittest.TextTestRunner(stream=sys.stdout, descriptions=False, verbosity=3) runner.run(test_suite())
def main(): """Handle command-line arguments and options.""" # as long as optional option values and negation are not implemented from optparse_optional import OptionalOptionParser usage = "%prog [ file1 dir1 dir2/glob*.od? dir3\.*\.od[ts] ] [options]" usage += os.linesep + __doc__ parser = OptionalOptionParser(usage) parser.add_option("--case-insensitive", dest="ignorecase", action="store_true", help="Ignore case for every file name matching.") parser.add_option("-d", "--directory", dest="directory", help="Write all output files to DIRECTORY.") parser.add_option("--exclude", dest="exclude", metavar="FILE", nargs=1, help="Found files must not match the exclude FILE pattern.") parser.add_option("--extension-append", dest="extension_append", action="store_true", help="Append an extension to each output FILE.") parser.add_option("--extension-replace", dest="extension_replace", action="store_true", help="Replace the extension of each output FILE.") parser.add_option("-f", "--file", dest="filename", metavar="FILE", help="Write to output FILE.") parser.add_option("--force", dest="force", action="store_true", help="Force overwriting of output FILE.") parser.add_option("-i", "--stdin", dest="stdin", action="store_true", oargs=1, metavar="[FILE]", help="Read one file from stdin before other input files\ [optional argument: output FILE].") parser.add_option("--include", dest="include", metavar="FILE", nargs=1, help="Found files must match the include FILE pattern.") parser.add_option("--list-authors", dest="list_author", action="store_true", oargs=1, help="Print a list of authors for all input files\ [optional argument: output FILE].", metavar="[FILE]") parser.add_option("-o", "--stdout", dest="stdout", action="store_true", help="Write to stdout in addition to output FILE.") parser.add_option("-q", "--quiet", dest="quiet", action="store_true", help="Don't print status messages to stdout.") parser.add_option("-r", "--replace", dest="replace", nargs=2, metavar="SEARCH REPLACE", help="Replace search string by replacement string.") parser.add_option("--recursive", dest="recursive", action="store_true", oargs=1, metavar="[LEVEL]", help="Search directories recursively\ [optional argument: maximum recursion LEVEL].") parser.add_option("--selftest", dest="selftest", action="store_true", help="Run the test suite.") parser.add_option("--tohtml", dest="tohtml", action="store_true", oargs=1, metavar="[FILE]", help="Convert the document to HTML\ [optional argument: output FILE].") parser.add_option("--toodf", dest="toodf", action="store_true", oargs=1, metavar="[FILE]", help="Convert the document to ODF\ [optional argument: output FILE].") parser.add_option("--totext", dest="totxt", action="store_true", oargs=1, metavar="[FILE]", help="Convert the document to plain text\ [optional argument: output FILE].") parser.add_option("--toxml", dest="toxml", action="store_true", oargs=1, metavar="[FILE]", help="Convert the document to XML\ [optional argument: output FILE].") parser.add_option("-v", "--verbose", dest="verbose", action="store_true", help="Print verbose status messages.") # TODO: options.pipe ? Read one file from stdin and write to stdout # TODO: options.encoding import sys, codecs # Encoding der Standardausgabe und des Dateisystems herausfinden # http://wiki.python.de/Von_Umlauten%2C_Unicode_und_Encodings # sys.getdefaultencoding() stdout_encoding = sys.stdout.encoding or sys.getfilesystemencoding() fs_encoding = sys.getfilesystemencoding() encoding = 'iso8859_15' # Decode all parameters to Unicode before parsing sys.argv = [s.decode(fs_encoding) for s in sys.argv] options, args = parser.parse_args() if options.verbose: verbosity = 2 elif options.quiet: verbosity = 0 else: verbosity = 1 if options.selftest: import unittest, tests stream = sys.stderr if options.filename: if not options.force and os.path.isfile(options.filename): print_unicode(sys.stderr, u'Warning: Skipping already existing output file "%s"' % options.filename, encoding) return stream = open(options.filename, 'w') elif options.stdout: stream = sys.stdout testrunner = unittest.TextTestRunner(stream=stream, verbosity=verbosity) testrunner.run(tests.test_suite()) if options.filename: stream.close() return filter = '' files = [] stdin = '' if parser.is_true(options.stdin): if not os.fstat(0)[6]: print >>sys.stderr, 'Warning: No input file data on stdin (i.e. use', print >>sys.stderr, '"cat a.ods | python odf.py --stdin").' else: try: # Windows needs stdio set for binary mode. import msvcrt msvcrt.setmode (0, os.O_BINARY) # stdin = 0 except ImportError: pass stdin = sys.stdin.read() if isinstance(options.recursive, tuple): if not options.recursive[0]: options.recursive = False else: options.recursive = int(options.recursive[1]) for arg in args: if os.path.isfile(arg): files.append(arg) else: try: path, filter = get_path_and_filter(arg) except PathNotFoundError, e: if verbosity == 2: print_unicode(sys.stderr, u'Warning: Skipping input file "' + arg + '":' + str(e), encoding) else: files.extend(list_directory(path, filter, options.ignorecase, options.recursive, False, options.include, options.exclude))
if xmlns: xmlns_items.append(xmlns) self.writeStartTagOpen(tag) # write attribute nodes for attrname, value in attributes: attrname, xmlns = self.addPrefix(attrname, namespaces) if xmlns: xmlns_items.append(xmlns) self.writeAttr(attrname, value) # write collected xmlns attributes for attrname, value in xmlns_items: self.writeAttr(attrname, value) if node.text or len(node): self.writeStartTagClose() if node.text: self.writeContent(node.text) for n in node: self.write(n, namespaces.copy()) self.writeEndTag(tag) else: self.writeEmptyTagClose() # for attrname, value in xmlns_items: # del namespaces[value] if node.tail: self.writeContent(node.tail) if __name__ == '__main__': from tests import test_suite suite = test_suite() unittest.TextTestRunner().run(suite)
#got the right number of args? If not, output help num_args = len(sys.argv) if num_args in [1]: print help sys.exit(0) if num_args >= 3: logger_names = sys.argv[2:] for logger_name in logger_names: logging.getLogger(logger_name).setLevel(logging.INFO) else: pass if sys.argv[1] == 'all': from tests import test_suite test_suite_obj = test_suite() unittest.TextTestRunner().run(test_suite_obj) else: module_name = sys.argv[1] if '.' in module_name: major_module_name = module_name.split('.')[0] #e.g. 'regressor' minor_module_name = module_name.split('.')[1] #e.g. 'Pwl' test_class_name = major_module_name + '.test.' + minor_module_name + 'Test' #e.g. 'regressor.test.PwlTest test_class = importString(test_class_name) #e.g. eval('import regressor.test.PwlTest') unittest_suite = unittest.makeSuite(test_class, 'test') test_suite = unittest_suite else: test_suite_name = module_name + '.test.test_suite' test_suite = importSuite(test_suite_name) result = unittest.TextTestRunner().run(test_suite)
import unittest import doctest import dkim from tests import test_suite doctest.testmod(dkim) unittest.TextTestRunner().run(test_suite())