Back to index

enigmail  1.4.3
test.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # ***** BEGIN LICENSE BLOCK *****
00004 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005 # 
00006 # The contents of this file are subject to the Mozilla Public License Version
00007 # 1.1 (the "License"); you may not use this file except in compliance with
00008 # the License. You may obtain a copy of the License at
00009 # http://www.mozilla.org/MPL/
00010 # 
00011 # Software distributed under the License is distributed on an "AS IS" basis,
00012 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 # for the specific language governing rights and limitations under the
00014 # License.
00015 # 
00016 # The Original Code is mozilla.org code.
00017 # 
00018 # The Initial Developer of the Original Code is
00019 # Mozilla.org.
00020 # Portions created by the Initial Developer are Copyright (C) 2010
00021 # the Initial Developer. All Rights Reserved.
00022 # 
00023 # Contributor(s):
00024 #     Jeff Hammel <jhammel@mozilla.com>     (Original author)
00025 # 
00026 # Alternatively, the contents of this file may be used under the terms of
00027 # either of the GNU General Public License Version 2 or later (the "GPL"),
00028 # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029 # in which case the provisions of the GPL or the LGPL are applicable instead
00030 # of those above. If you wish to allow use of your version of this file only
00031 # under the terms of either the GPL or the LGPL, and not to allow others to
00032 # use your version of this file under the terms of the MPL, indicate your
00033 # decision by deleting the provisions above and replace them with the notice
00034 # and other provisions required by the GPL or the LGPL. If you do not delete
00035 # the provisions above, a recipient may use your version of this file under
00036 # the terms of any one of the MPL, the GPL or the LGPL.
00037 # 
00038 # ***** END LICENSE BLOCK *****
00039 
00040 """tests for ManifestDestiny"""
00041 
00042 import doctest
00043 import os
00044 import sys
00045 from optparse import OptionParser
00046 
00047 def run_tests(raise_on_error=False, report_first=False):
00048 
00049     # add results here
00050     results = {}
00051 
00052     # doctest arguments
00053     directory = os.path.dirname(os.path.abspath(__file__))
00054     extraglobs = {}
00055     doctest_args = dict(extraglobs=extraglobs,
00056                         module_relative=False,
00057                         raise_on_error=raise_on_error)
00058     if report_first:
00059         doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE
00060                                 
00061     # gather tests
00062     directory = os.path.dirname(os.path.abspath(__file__))
00063     tests =  [ test for test in os.listdir(directory)
00064                if test.endswith('.txt') and test.startswith('test_')]
00065     os.chdir(directory)
00066 
00067     # run the tests
00068     for test in tests:
00069         try:
00070             results[test] = doctest.testfile(test, **doctest_args)
00071         except doctest.DocTestFailure, failure:
00072             raise
00073         except doctest.UnexpectedException, failure:
00074             raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
00075         
00076     return results
00077                                 
00078 
00079 def main(args=sys.argv[1:]):
00080 
00081     # parse command line options
00082     parser = OptionParser(description=__doc__)
00083     parser.add_option('--raise', dest='raise_on_error',
00084                       default=False, action='store_true',
00085                       help="raise on first error")
00086     parser.add_option('--report-first', dest='report_first',
00087                       default=False, action='store_true',
00088                       help="report the first error only (all tests will still run)")
00089     parser.add_option('-q', '--quiet', dest='quiet',
00090                       default=False, action='store_true',
00091                       help="minimize output")
00092     options, args = parser.parse_args(args)
00093     quiet = options.__dict__.pop('quiet')
00094 
00095     # run the tests
00096     results = run_tests(**options.__dict__)
00097 
00098     # check for failure
00099     failed = False
00100     for result in results.values():
00101         if result[0]: # failure count; http://docs.python.org/library/doctest.html#basic-api
00102             failed = True
00103             break
00104     if failed:
00105         sys.exit(1) # error
00106     if not quiet:
00107         # print results
00108         print "manifestparser.py: All tests pass!"
00109         for test in sorted(results.keys()):
00110             result = results[test]
00111             print "%s: failed=%s, attempted=%s" % (test, result[0], result[1])
00112                
00113 if __name__ == '__main__':
00114     main()