diff tests/test.py @ 87:29ca60f428cc

STUB: tests/test.py tests/test_include.txt
author Jeff Hammel <k0scist@gmail.com>
date Fri, 21 Mar 2014 22:27:51 -0700
parents daf3a05a05fe
children
line wrap: on
line diff
--- a/tests/test.py	Fri Mar 21 22:04:17 2014 -0700
+++ b/tests/test.py	Fri Mar 21 22:27:51 2014 -0700
@@ -4,10 +4,11 @@
 run tests for pyloader
 """
 
+# imports
+import argparse
 import doctest
 import os
 import sys
-from optparse import OptionParser
 
 directory = os.path.dirname(os.path.abspath(__file__))
 
@@ -44,29 +45,41 @@
     return results
 
 def main(args=sys.argv[1:]):
+    """test runner CLI"""
 
     # parse command line args
-    parser = OptionParser(description=__doc__)
-    parser.add_option('--list', dest='list_tests',
-                      action='store_true', default=False,
-                      help="list tests and exit")
-    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)
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument('tests', metavar='test', nargs="*",
+                        help="tests to run; if omitted, run all")
+    parser.add_argument('--list', dest='list_tests',
+                        action='store_true', default=False,
+                        help="list tests and exit")
+    parser.add_argument('--raise', dest='raise_on_error',
+                        default=False, action='store_true',
+                        help="raise on first error")
+    parser.add_argument('--report-first', dest='report_first',
+                        default=False, action='store_true',
+                        help="report the first error only (all tests will still run)")
+    options = parser.parse_args(args)
 
-    # gathe tests
+    # gather tests
     tests = gather()
 
+    # filter tests
+    if options.tests:
+        missing = set(options.tests).difference(tests)
+        if missing:
+            parser.error("Test files not found: {0}; Should be in {1}".format(', '.join(missing),
+                                                                              ', '.join(tests)))
+        tests = options.tests
+
     if options.list_tests:
         print ("\n".join(tests))
         sys.exit()
 
     # run the tests
-    results = run_tests(report_first=options.report_first,
+    results = run_tests(tests=tests,
+                        report_first=options.report_first,
                         raise_on_error=options.raise_on_error)
     if sum([i.failed for i in results.values()]):
         sys.exit(1) # error