changeset 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 2c315267390b
children dd8ad435cb26
files tests/test.py tests/test_include.txt
diffstat 2 files changed, 31 insertions(+), 15 deletions(-) [+]
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
--- a/tests/test_include.txt	Fri Mar 21 22:04:17 2014 -0700
+++ b/tests/test_include.txt	Fri Mar 21 22:27:51 2014 -0700
@@ -1,6 +1,9 @@
 Test IniFactory
 ===============
 
-Let's test the .ini factory::
+Let's test file inclusion.  First a simple example without it for comparison::
 
     >>> import os
+    >>> from pyloader.factory import IniFactory
+    >>> inifile = os.path.join(here, 'test.ini')
+    >>> inifactory = IniFactory(inifile)