changeset 116:9d19ed8fd883

https://bugzilla.mozilla.org/show_bug.cgi?id=796196
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 01 Oct 2012 17:08:45 -0700
parents 56db0b2b90af
children dd3480af4cd5
files configuration/configuration.py setup.py tests/unit.py
diffstat 3 files changed, 32 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/configuration.py	Wed Jul 04 09:54:37 2012 -0700
+++ b/configuration/configuration.py	Mon Oct 01 17:08:45 2012 -0700
@@ -254,6 +254,7 @@
         self.config = {}
         self.configuration_providers = configuration_providers
         self.types = types
+        self.added = set() # set of items added to the configuration
 
         # setup optionparser
         if 'description' not in parser_args:
@@ -357,6 +358,7 @@
 
     def __call__(self, *args):
         """add items to configuration and check it"""
+        # TODO: configuration should be locked after this is called
 
         # start with defaults
         self.config = self.default_config()
@@ -367,7 +369,9 @@
 
         # validate total configuration
         self.validate()
-        # TODO: configuration should be locked after this is called
+
+        # return the configuration
+        return self.config
 
     def add(self, config, check=True):
         """update configuration: not undoable"""
@@ -390,6 +394,8 @@
                     raise NotImplementedError
             else:
                 self.config[key] = value
+            self.added.add(key)
+
 
     ### methods for optparse
     ### XXX could go in a subclass
--- a/setup.py	Wed Jul 04 09:54:37 2012 -0700
+++ b/setup.py	Mon Oct 01 17:08:45 2012 -0700
@@ -4,7 +4,7 @@
 
 import os
 
-version = "0.3"
+version = "0.3.1"
 dependencies = ['PyYAML']
 
 try:
--- a/tests/unit.py	Wed Jul 04 09:54:37 2012 -0700
+++ b/tests/unit.py	Mon Oct 01 17:08:45 2012 -0700
@@ -203,5 +203,29 @@
         expected = datetime.datetime(2012, 7, 4, 0, 0)
         self.assertEqual(example.config['datestring'], expected)
 
+
+    def test_added(self):
+        """test that we keep track of things added to the configuration"""
+
+        # make an example class
+        class AddedExample(configuration.Configuration):
+            options = {'foo': {},
+                       'bar': {}}
+
+        # parse it; there should be nothing
+        instance = AddedExample()
+        instance()
+        self.assertEqual(instance.added, set())
+
+        # parse it; there should be one thing
+        instance = AddedExample()
+        instance({'foo': 'foo'})
+        self.assertEqual(instance.added, set(['foo']))
+
+        # parse it; there should be two things
+        instance = AddedExample()
+        instance({'foo': 'foo'}, {'foo': 'FOO', 'bar': 'bar'})
+        self.assertEqual(instance.added, set(['foo', 'bar']))
+
 if __name__ == '__main__':
     unittest.main()