run-tests: allow option parser to be extended stable
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 24 Mar 2014 21:52:28 -0700
branchstable
changeset 1365 51476d2dcab1
parent 1364 772a53435e14
child 1366 987a80dec7db
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. [ original upstream message ]
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()