Rev 5777: Parametrize the Stack tests. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue May 3 17:44:32 UTC 2011


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

------------------------------------------------------------
revno: 5777
revision-id: v.ladeuil+lp at free.fr-20110503174432-ev6v5trxovczuu0w
parent: v.ladeuil+lp at free.fr-20110503162706-kkpdfdix35li5y04
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-concrete-stacks
timestamp: Tue 2011-05-03 19:44:32 +0200
message:
  Parametrize the Stack tests.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-05-03 16:27:06 +0000
+++ b/bzrlib/config.py	2011-05-03 17:44:32 +0000
@@ -998,6 +998,12 @@
         # the other hand, this means 'file://' urls *can't* be used in sections
         # so more work is probably needed -- vila 2011-04-07
 
+        # FIXME: And last one: LocationStore allows a no-name section which
+        # always matches as the most generic one, this is not supposed to
+        # happen with LocationConfig but doesn't hurt either
+        if section is None:
+            yield section, location, 0
+            continue
         if section.startswith('file://'):
             section_path = urlutils.local_path_from_url(section)
         else:
@@ -2270,7 +2276,11 @@
         :returns: An iterable of (name, dict).
         """
         # We need a loaded store
-        self.load()
+        try:
+            self.load()
+        except errors.NoSuchFile:
+            # If the file doesn't exist, there is no sections
+            return
         cobj = self._config_obj
         if cobj.scalars:
             yield self.readonly_section_class(None, cobj)
@@ -2415,7 +2425,7 @@
         # Override the default implementation as we want to change the order
 
         # The following is a bit hackish but ensures compatibility with
-        # LocationConfig by reusing the same code
+        # LocationConfig by reusing the same code (_iter_for_location_by_parts)
         sections = list(self.store.get_sections())
         filtered_sections = _iter_for_location_by_parts(
             [s.id for s in sections], self.location)
@@ -2477,7 +2487,7 @@
         # FIXME: No caching of options nor sections yet -- vila 20110503
 
         # Ensuring lazy loading is achieved by delaying section matching until
-        # it can be avoided anymore by using callables to describe (possibly
+        # it can't be avoided anymore by using callables to describe (possibly
         # empty) section lists.
         for section_or_callable in self.sections_def:
             # Each section can expand to multiple ones when a callable is used
@@ -2498,7 +2508,7 @@
         This is where we guarantee that the mutable section is lazily loaded:
         this means we won't load the corresponding store before setting a value
         or deleting an option. In practice the store will often be loaded but
-        this allows catching some programming errors.
+        this allows helps catching some programming errors.
         """
         section = self.store.get_mutable_section(self.mutable_section_name)
         return section
@@ -2523,8 +2533,7 @@
     def __init__(self):
         # Get a GlobalStore
         gstore = GlobalStore()
-        super(GlobalStack, self).__init__([gstore.get_sections],
-                                          gstore.get_mutable_section)
+        super(GlobalStack, self).__init__([gstore.get_sections], gstore)
 
 
 class LocationStack(Stack):
@@ -2534,8 +2543,7 @@
         matcher = LocationMatcher(lstore, location)
         gstore = GlobalStore()
         super(LocationStack, self).__init__(
-            [matcher.get_sections, gstore.get_sections],
-            lstore.get_mutable_section)
+            [matcher.get_sections, gstore.get_sections], lstore)
 
 
 class BranchStack(Stack):
@@ -2547,7 +2555,7 @@
         gstore = GlobalStore()
         super(BranchStack, self).__init__(
             [matcher.get_sections, bstore.get_sections, gstore.get_sections],
-            bstore.get_mutable_section)
+            bstore)
 
 
 class cmd_config(commands.Command):

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-05-03 16:27:06 +0000
+++ b/bzrlib/tests/test_config.py	2011-05-03 17:44:32 +0000
@@ -2222,56 +2222,57 @@
         self.assertRaises(TypeError, conf_stack.get, 'foo')
 
 
-class TestStackSet(tests.TestCaseWithTransport):
-
-    # FIXME: This should be parametrized for all known Stack or dedicated
-    # paramerized tests created to avoid bloating -- vila 2011-04-05
+class TestStackWithTransport(tests.TestCaseWithTransport):
+
+    def setUp(self):
+        super(TestStackWithTransport, self).setUp()
+        # FIXME: A more elaborate builder for the stack would avoid building a
+        # branch even for tests that don't need it.
+        self.branch = self.make_branch('branch')
+
+
+class TestStackSet(TestStackWithTransport):
+
+    scenarios = [(key, {'get_stack': builder})
+                 for key, builder in test_stack_builder_registry.iteritems()]
 
     def test_simple_set(self):
-        store = config.IniFileStore(self.get_transport(), 'test.conf')
-        store._load_from_string('foo=bar')
-        conf = config.Stack([store.get_sections], store)
+        conf = self.get_stack(self)
+        conf.store._load_from_string('foo=bar')
         self.assertEquals('bar', conf.get('foo'))
         conf.set('foo', 'baz')
         # Did we get it back ?
         self.assertEquals('baz', conf.get('foo'))
 
     def test_set_creates_a_new_section(self):
-        store = config.IniFileStore(self.get_transport(), 'test.conf')
-        conf = config.Stack([store.get_sections], store)
+        conf = self.get_stack(self)
         conf.set('foo', 'baz')
         self.assertEquals, 'baz', conf.get('foo')
 
 
-class TestStackRemove(tests.TestCaseWithTransport):
+class TestStackRemove(TestStackWithTransport):
 
-    # FIXME: This should be parametrized for all known Stack or dedicated
-    # paramerized tests created to avoid bloating -- vila 2011-04-06
+    scenarios = [(key, {'get_stack': builder})
+                 for key, builder in test_stack_builder_registry.iteritems()]
 
     def test_remove_existing(self):
-        store = config.IniFileStore(self.get_transport(), 'test.conf')
-        store._load_from_string('foo=bar')
-        conf = config.Stack([store.get_sections], store)
+        conf = self.get_stack(self)
+        conf.store._load_from_string('foo=bar')
         self.assertEquals('bar', conf.get('foo'))
         conf.remove('foo')
         # Did we get it back ?
         self.assertEquals(None, conf.get('foo'))
 
     def test_remove_unknown(self):
-        store = config.IniFileStore(self.get_transport(), 'test.conf')
-        conf = config.Stack([store.get_sections], store)
+        conf = self.get_stack(self)
         self.assertRaises(KeyError, conf.remove, 'I_do_not_exist')
 
 
-class TestConcreteStacks(tests.TestCaseWithTransport):
+class TestConcreteStacks(TestStackWithTransport):
 
     scenarios = [(key, {'get_stack': builder})
                  for key, builder in test_stack_builder_registry.iteritems()]
 
-    def setUp(self):
-        super(TestConcreteStacks, self).setUp()
-        self.branch = self.make_branch('branch')
-
     def test_build_stack(self):
         stack = self.get_stack(self)
 



More information about the bazaar-commits mailing list