changeset 36:d218df4d0b4c

add test for missing values
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 27 Mar 2012 09:40:15 -0700
parents 321fe58a9eae
children a1f8dec4d4f9
files configuration/config.py tests/unit.py
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/config.py	Tue Mar 27 09:35:21 2012 -0700
+++ b/configuration/config.py	Tue Mar 27 09:40:15 2012 -0700
@@ -21,7 +21,12 @@
 except ImportError:
     yaml = None
 
-__all__ = ['Configuration', 'configuration_providers', 'types']
+__all__ = ['Configuration', 'configuration_providers', 'types', 'MissingValueException']
+
+### exceptions
+
+class MissingValueException(Exception):
+    """exception raised when a required value is missing"""
 
 ### configuration providers for serialization/deserialization
 
@@ -198,7 +203,7 @@
                     else:
                         required_message = "Parameter %s is required but not present" % key
                     # TODO: more specific exception
-                    raise Exception(required_message)
+                    raise MissingValueException(required_message)
         # TODO: configuration should be locked after this is called
 
     ### methods for adding configuration
--- a/tests/unit.py	Tue Mar 27 09:35:21 2012 -0700
+++ b/tests/unit.py	Tue Mar 27 09:40:15 2012 -0700
@@ -61,6 +61,19 @@
         if os.path.exists(filename):
             os.remove(filename)
 
+    def test_required(self):
+        """ensure you have to have required values"""
+
+        example = ExampleConfiguration()
+
+        # ensure you get an exception
+        missingvalueexception = None
+        try:
+            example()
+        except configuration.MissingValueException, e:
+            missingvalueexception = e
+        self.assertTrue(isinstance(e, configuration.MissingValueException))
+
 if __name__ == '__main__':
     unittest.main()