# HG changeset patch # User Jeff Hammel # Date 1349136525 25200 # Node ID 9d19ed8fd883acbe6669a9e7c3942791a129281f # Parent 56db0b2b90af326959f72bd49673d8bdb6b40cfe https://bugzilla.mozilla.org/show_bug.cgi?id=796196 diff -r 56db0b2b90af -r 9d19ed8fd883 configuration/configuration.py --- 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 diff -r 56db0b2b90af -r 9d19ed8fd883 setup.py --- 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: diff -r 56db0b2b90af -r 9d19ed8fd883 tests/unit.py --- 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()