Back to index

enigmail  1.4.3
Functions
test Namespace Reference

Functions

def run_tests
def main

Function Documentation

def test.main (   args = sys.argv[1:])

Definition at line 79 of file test.py.

00079 
00080 def main(args=sys.argv[1:]):
00081 
00082     # parse command line options
00083     parser = OptionParser(description=__doc__)
00084     parser.add_option('--raise', dest='raise_on_error',
00085                       default=False, action='store_true',
00086                       help="raise on first error")
00087     parser.add_option('--report-first', dest='report_first',
00088                       default=False, action='store_true',
00089                       help="report the first error only (all tests will still run)")
00090     parser.add_option('-q', '--quiet', dest='quiet',
00091                       default=False, action='store_true',
00092                       help="minimize output")
00093     options, args = parser.parse_args(args)
00094     quiet = options.__dict__.pop('quiet')
00095 
00096     # run the tests
00097     results = run_tests(**options.__dict__)
00098 
00099     # check for failure
00100     failed = False
00101     for result in results.values():
00102         if result[0]: # failure count; http://docs.python.org/library/doctest.html#basic-api
00103             failed = True
00104             break
00105     if failed:
00106         sys.exit(1) # error
00107     if not quiet:
00108         # print results
00109         print "manifestparser.py: All tests pass!"
00110         for test in sorted(results.keys()):
00111             result = results[test]
00112             print "%s: failed=%s, attempted=%s" % (test, result[0], result[1])
               

Here is the call graph for this function:

def test.run_tests (   raise_on_error = False,
  report_first = False 
)

Definition at line 47 of file test.py.

00047 
00048 def run_tests(raise_on_error=False, report_first=False):
00049 
00050     # add results here
00051     results = {}
00052 
00053     # doctest arguments
00054     directory = os.path.dirname(os.path.abspath(__file__))
00055     extraglobs = {}
00056     doctest_args = dict(extraglobs=extraglobs,
00057                         module_relative=False,
00058                         raise_on_error=raise_on_error)
00059     if report_first:
00060         doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE
00061                                 
00062     # gather tests
00063     directory = os.path.dirname(os.path.abspath(__file__))
00064     tests =  [ test for test in os.listdir(directory)
00065                if test.endswith('.txt') and test.startswith('test_')]
00066     os.chdir(directory)
00067 
00068     # run the tests
00069     for test in tests:
00070         try:
00071             results[test] = doctest.testfile(test, **doctest_args)
00072         except doctest.DocTestFailure, failure:
00073             raise
00074         except doctest.UnexpectedException, failure:
00075             raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
00076         
00077     return results
00078                                 

Here is the caller graph for this function: