changeset 19:cadc9514f60a

we have a legitimately failing test!
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 26 Mar 2012 13:54:43 -0700
parents d8871956536e
children dbfabe96187e
files configuration/config.py tests/example.py tests/unit.py
diffstat 3 files changed, 23 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/config.py	Mon Mar 26 13:19:55 2012 -0700
+++ b/configuration/config.py	Mon Mar 26 13:54:43 2012 -0700
@@ -121,3 +121,14 @@
         parser = optparse.OptionParser(**parser_args)
         self.optparse_options(parser)
         return parser
+
+    def parse(self, args=sys.argv[1:], parser=None):
+        """parse configuration including command line options"""
+
+        # parse arguments
+        if parser is None:
+            parser = self.parser()
+        options, args = parser.parse_args(args)
+
+        # return parsed arguments
+        return options, args
--- a/tests/example.py	Mon Mar 26 13:19:55 2012 -0700
+++ b/tests/example.py	Mon Mar 26 13:54:43 2012 -0700
@@ -10,9 +10,11 @@
         'title': {'help': 'talos run title'},
         'browser_path': {'required': True,
                          'flags': ['-e', '--executablePath'],
-                         'help': 'path to firefox'}
+                         'help': 'path to firefox'},
+        'develop': {'help': "useful for running tests on a developer machine. Creates a local webserver and doesn't upload to the graph servers.",
+                    'type': bool}
         }
 
 if __name__ == '__main__':
-    parser = ExampleConfiguration().parser()
-    parser.parse_args()
+    options, args = ExampleConfiguration().parse()
+
--- a/tests/unit.py	Mon Mar 26 13:19:55 2012 -0700
+++ b/tests/unit.py	Mon Mar 26 13:54:43 2012 -0700
@@ -8,7 +8,7 @@
 import sys
 import unittest
 
-import example # example configuration to test
+from example import ExampleConfiguration # example configuration to test
 
 # globals
 here = os.path.dirname(os.path.abspath(__file__))
@@ -16,7 +16,12 @@
 class configurationUnitTest(unittest.TestCase):
 
     def test_configuration(self):
-        
+        example = ExampleConfiguration()
+
+        # parse command line arguments
+        options, args = example.parse(['-a', 'ts', '--develop', '-e', '/home/jhammel/bin/firefox'])
+        self.assertEqual(bool(args), False) # no arguments
+        self.assertEqual(options.develop, True)
 
 if __name__ == '__main__':
     unittest.main()