[tracker] functional-tests: Use environment vars instead of commandline options



commit 9d2c47bb1d8f6a4bfcf7b16dc91e7f6d186e53c8
Author: Sam Thursfield <sam afuera me uk>
Date:   Sat Oct 10 22:01:55 2015 +0200

    functional-tests: Use environment vars instead of commandline options
    
    The commandline option parsing is totally broken and interferes with the
    real argument parsing of the unittest module or whatever other test
    runner you are using.
    
    You can now enable verbose test output by setting
    TRACKER_TESTS_VERBOSE=1 in the environment. The
    TRACKER_TESTS_MANUAL_START variable also exists but probably doesn't
    work at present.

 tests/functional-tests/common/utils/options.py |   43 ++++++++---------------
 1 files changed, 15 insertions(+), 28 deletions(-)
---
diff --git a/tests/functional-tests/common/utils/options.py b/tests/functional-tests/common/utils/options.py
index 6bc8379..1b46cad 100644
--- a/tests/functional-tests/common/utils/options.py
+++ b/tests/functional-tests/common/utils/options.py
@@ -1,38 +1,25 @@
-from optparse import OptionParser
-import sys
+import os
 
-usage = "usage: %prog [options]"
+def get_environment_boolean(variable):
+    '''Parse a yes/no boolean passed through the environment.'''
 
-parser = OptionParser(usage=usage)
+    value = os.environ.get(variable, 'no').lower()
+    if value in ['no', '0', 'false']:
+        return False
+    elif value in ['yes', '1', 'true']:
+        return True
+    else:
+        raise RuntimeError('Unexpected value for %s: %s' %
+                           (variable, value))
 
-parser.add_option("-m", "--start-manually", dest="startmanually",
-                  action="store_true",
-                  default=False,
-                  help="Wait for an external instance of the processes to appear in the system")
-
-parser.add_option("-v", "--verbose", dest="verbose",
-                  action="store_true",
-                  default=False,
-                  help="Display a log of test process statuses")
-
-(options, args) = parser.parse_args()
-
-# Deleting options from the args. Otherwise unittest and the tests which
-# have their own simple commandline parsers will complain
-for option in ["--startmanually", "-m", "--verbose", "-v"]:
-    try:
-        sys.argv.remove (option)
-    except ValueError:
-        pass
-
-def is_verbose ():
+def is_verbose():
     """
     True to log process status information to stdout
     """
-    return options.verbose
+    return get_environment_boolean('TRACKER_TESTS_VERBOSE')
 
-def is_manual_start ():
+def is_manual_start():
     """
     False to start the processes automatically
     """
-    return options.startmanually
+    return get_environment_boolean('TRACKER_TESTS_MANUAL_START')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]