Rev 5752: Fix the issue by allowing delayed section acquisition. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Apr 5 16:46:34 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5752
revision-id: v.ladeuil+lp at free.fr-20110405164634-tq2gnd52yl7gclh5
parent: v.ladeuil+lp at free.fr-20110405161052-1swij0q6zfb9un26
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-stack
timestamp: Tue 2011-04-05 18:46:34 +0200
message:
  Fix the issue by allowing delayed section acquisition.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-05 15:26:46 +0000
+++ b/bzrlib/config.py	2011-04-05 16:46:34 +0000
@@ -2168,20 +2168,21 @@
 class ConfigStack(object):
     """A stack of configurations where an option can be defined"""
 
-    def __init__(self, config_list, store=None):
-        self.list = config_list
-        for c in self.list:
-            # Sanity check
-            if not hasattr(c, 'get'):
-                raise AssertionError("%r does not provide a 'get' method"
-                                     % (c,))
+    def __init__(self, sections, store=None):
+        self.sections = sections
         self.store = store
 
     def get(self, name):
         """Return the value from the first definition found in the list"""
         value = None
-        for c in self.list:
-            value = c.get(name)
+        for s in self.sections:
+            if callable(s):
+                for s in s():
+                    value = s.get(name)
+                    if value is not None:
+                        break
+            else:
+                value = s.get(name)
             if value is not None:
                 break
         return value

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-04-05 16:10:52 +0000
+++ b/bzrlib/tests/test_config.py	2011-04-05 16:46:34 +0000
@@ -2023,14 +2023,12 @@
         b = self.make_branch('.')
         store = config.BranchStore(b)
 
+
 class TestConfigStackGet(tests.TestCase):
 
     # FIXME: This should be parametrized for all known ConfigStack or dedicated
     # paramerized tests created to avoid bloating -- vila 2011-03-31
 
-    def test_compatibility(self):
-        self.assertRaises(AssertionError, config.ConfigStack, [object()])
-
     def test_single_config_get(self):
         conf = dict(foo='bar')
         conf_stack = config.ConfigStack([conf])
@@ -2066,11 +2064,9 @@
     def test_set_creates_a_new_section(self):
         store = config.ConfigObjStore.from_string(
             '', self.get_transport(), 'test.conf')
-        conf = config.ConfigStack(list(store.get_sections()), store)
+        conf = config.ConfigStack([store.get_sections], store)
         conf.set('foo', 'baz')
-        self.expectFailure(
-            'Newly created sections were not known at stack build time',
-            self.assertEquals, 'baz', conf.get('foo'))
+        self.assertEquals, 'baz', conf.get('foo')
 
 
 class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):



More information about the bazaar-commits mailing list