run-tests: allow option parser to be extended
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 24 Mar 2014 21:52:28 -0700
changeset 21008 c1dd04be3d9a
parent 21007 57179a4bf77a
child 21009 990f5392c018
run-tests: allow option parser to be extended This patch moves the OptionParser population into its own function so consumers may modify the OptionParser before arguments are evaluated. This will allow consumers to add custom options, set different defaults, etc.
tests/run-tests.py
--- a/tests/run-tests.py	Mon Mar 24 21:41:56 2014 -0700
+++ b/tests/run-tests.py	Mon Mar 24 21:52:28 2014 -0700
@@ -133,7 +133,7 @@
         f.close()
     return entries
 
-def parseargs(args):
+def getparser():
     parser = optparse.OptionParser("%prog [options] [tests]")
 
     # keep these sorted
@@ -210,6 +210,10 @@
     for option, (envvar, default) in defaults.items():
         defaults[option] = type(default)(os.environ.get(envvar, default))
     parser.set_defaults(**defaults)
+
+    return parser
+
+def parseargs(args, parser):
     (options, args) = parser.parse_args(args)
 
     # jython is always pure
@@ -1176,8 +1180,9 @@
 testtypes = [('.py', pytest, '.out'),
              ('.t', tsttest, '')]
 
-def main(args):
-    (options, args) = parseargs(args)
+def main(args, parser=None):
+    parser = parser or getparser()
+    (options, args) = parseargs(args, parser)
     os.umask(022)
 
     checktools()