changeset 141:4ee086606772

add extra data
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 29 Feb 2012 10:42:44 -0800
parents 3046e15c3dd7
children a203f79c537f
files makeitso/python_module/README.txt makeitso/python_module/tests/doctest.txt makeitso/python_module/tests/test.py
diffstat 3 files changed, 79 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/makeitso/python_module/README.txt	Wed Feb 29 10:42:44 2012 -0800
@@ -0,0 +1,10 @@
+{{project}}
+===========
+
+{{description}}
+
+----
+
+{{author}}
+
+{{url}}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/makeitso/python_module/tests/doctest.txt	Wed Feb 29 10:42:44 2012 -0800
@@ -0,0 +1,10 @@
+Test {{project}}
+================
+
+The obligatory imports:
+
+    >>> import {{package}}
+
+Run some tests.  This test will fail, please fix it:
+
+    >>> assert True == False
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/makeitso/python_module/tests/test.py	Wed Feb 29 10:42:44 2012 -0800
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+
+"""
+doctest runner
+"""
+
+import doctest
+import os
+import sys
+from optparse import OptionParser
+
+
+def run_tests(raise_on_error=False, report_first=False):
+
+    # add results here
+    results = {}
+
+    # doctest arguments
+    directory = os.path.dirname(os.path.abspath(__file__))
+    extraglobs = {'here': directory}
+    doctest_args = dict(extraglobs=extraglobs, raise_on_error=raise_on_error)
+    if report_first:
+        doctest_args['optionflags'] = doctest.REPORT_ONLY_FIRST_FAILURE
+
+    # gather tests
+    tests =  [ test for test in os.listdir(directory)
+               if test.endswith('.txt') ]
+
+    # run the tests
+    for test in tests:
+        try:
+            results[test] = doctest.testfile(test, **doctest_args)
+        except doctest.DocTestFailure, failure:
+            raise
+        except doctest.UnexpectedException, failure:
+            raise failure.exc_info[0], failure.exc_info[1], failure.exc_info[2]
+
+    return results
+
+def main(args=sys.argv[1:]):
+
+    # parse command line args
+    parser = OptionParser(description=__doc__)
+    parser.add_option('--raise', dest='raise_on_error',
+                      default=False, action='store_true',
+                      help="raise on first error")
+    parser.add_option('--report-first', dest='report_first',
+                      default=False, action='store_true',
+                      help="report the first error only (all tests will still run)")
+    options, args = parser.parse_args(args)
+
+    # run the tests
+    results = run_tests(**options.__dict__)
+    if sum([i.failed for i in results.values()]):
+        sys.exit(1) # error
+                
+
+if __name__ == '__main__':
+    main()