Rev 5544: Merge config-save-each-modif into doc-new-config in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat May 14 15:46:02 UTC 2011


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

------------------------------------------------------------
revno: 5544 [merge]
revision-id: v.ladeuil+lp at free.fr-20110514154602-nt0j90htbx8lumad
parent: v.ladeuil+lp at free.fr-20110511170251-47wm2ay8ne56c18n
parent: v.ladeuil+lp at free.fr-20110514154600-rvq6zqyznjij127r
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: doc-new-config
timestamp: Sat 2011-05-14 17:46:02 +0200
message:
  Merge config-save-each-modif into doc-new-config
modified:
  bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
  bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-05-11 17:01:00 +0000
+++ b/bzrlib/config.py	2011-05-13 15:19:31 +0000
@@ -2362,7 +2362,10 @@
         super(LocationStore, self).__init__(t, 'locations.conf')
 
 
-class BranchStore(IniFileStore):
+# FIXME: We should rely on the branch itself to be locked (possibly checking
+# that even) but we shouldn't lock ourselves. This may make `bzr config` is
+# abit trickier though but I punt for now -- vila 20110512
+class BranchStore(LockableIniFileStore):
 
     def __init__(self, branch):
         super(BranchStore, self).__init__(branch.control_transport,
@@ -2542,7 +2545,14 @@
 
 
 class _CompatibleStack(Stack):
-    """Place holder for compatibility with previous design."""
+    """Place holder for compatibility with previous design.
+
+    This intended to ease the transition from the Config-based design to the
+    Stack-based design and should not be used nor relied upon by plugins.
+
+    One assumption made here is that the daughter classes will all use Stores
+    derived from LockableIniFileStore).
+    """
 
     def set(self, name, value):
         # Force a reload (assuming we use a LockableIniFileStore)
@@ -2569,8 +2579,8 @@
         super(LocationStack, self).__init__(
             [matcher.get_sections, gstore.get_sections], lstore)
 
-
-class BranchStack(Stack):
+# FIXME: See BranchStore, same remarks -- vila 20110512
+class BranchStack(_CompatibleStack):
 
     def __init__(self, branch):
         bstore = BranchStore(branch)
@@ -2745,3 +2755,23 @@
             raise errors.NoSuchConfig(scope)
         if not removed:
             raise errors.NoSuchConfigOption(name)
+
+
+# Test registries
+
+# We need adapters that can build a Store or a Stack in a test context. Test
+# classes, based on TestCaseWithTransport, can use the registry to parametrize
+# themselves. The builder will receive a test instance and should return a
+# ready-to-use store or stack.  Plugins that defines new store/stacks can also
+# register themselves here to be tested against the tests defined in
+# bzrlib.tests.test_config.
+
+# The registered object should be a callable receiving a test instance
+# parameter (inheriting from tests.TestCaseWithTransport) and returning a Store
+# object.
+test_store_builder_registry = registry.Registry()
+
+# Thre registered object should be a callable receiving a test instance
+# parameter (inheriting from tests.TestCaseWithTransport) and returning a Stack
+# object.
+test_stack_builder_registry = registry.Registry()

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-05-11 17:01:00 +0000
+++ b/bzrlib/tests/test_config.py	2011-05-13 15:19:31 +0000
@@ -63,44 +63,33 @@
 
 load_tests = scenarios.load_tests_apply_scenarios
 
-# We need adapters that can build a config store in a test context. Test
-# classes, based on TestCaseWithTransport, can use the registry to parametrize
-# themselves. The builder will receive a test instance and should return a
-# ready-to-use store.  Plugins that defines new stores can also register
-# themselves here to be tested against the tests defined below.
-
-# FIXME: plugins should *not* need to import test_config to register their
-# helpers (or selftest -s xxx will be broken), the following registry should be
-# moved to bzrlib.config instead so that selftest -s bt.test_config also runs
-# the plugin specific tests (selftest -s bp.xxx won't, that would be against
-# the spirit of '-s') -- vila 20110503
-test_store_builder_registry = registry.Registry()
-test_store_builder_registry.register(
+# Register helpers to build stores
+config.test_store_builder_registry.register(
     'configobj', lambda test: config.IniFileStore(test.get_transport(),
                                                   'configobj.conf'))
-test_store_builder_registry.register(
+config.test_store_builder_registry.register(
     'bazaar', lambda test: config.GlobalStore())
-test_store_builder_registry.register(
+config.test_store_builder_registry.register(
     'location', lambda test: config.LocationStore())
-test_store_builder_registry.register(
-    'branch', lambda test: config.BranchStore(test.branch))
-
-# FIXME: Same remark as above for the following registry -- vila 20110503
-test_stack_builder_registry = registry.Registry()
-test_stack_builder_registry.register(
-    'bazaar', lambda test: config.GlobalStack())
-test_stack_builder_registry.register(
-    'location', lambda test: config.LocationStack('.'))
-test_stack_builder_registry.register(
-    'branch', lambda test: config.BranchStack(test.branch))
-
-# FIXME: Same remark as above for the following registry, which makes three of
-# them, we'll soon be able to triangulate ;) -- vila 20110509
-test_compatible_stack_builder_registry = registry.Registry()
-test_compatible_stack_builder_registry.register(
-    'bazaar', lambda test: config.GlobalStack())
-test_compatible_stack_builder_registry.register(
-    'location', lambda test: config.LocationStack('.'))
+
+def build_branch_store(test):
+    if getattr(test, 'branch', None) is None:
+        test.branch = test.make_branch('branch')
+    return config.BranchStore(test.branch)
+config.test_store_builder_registry.register('branch', build_branch_store)
+
+
+config.test_stack_builder_registry.register(
+    'bazaar', lambda test: config.GlobalStack())
+config.test_stack_builder_registry.register(
+    'location', lambda test: config.LocationStack('.'))
+
+def build_branch_stack(test):
+    if getattr(test, 'branch', None) is None:
+        test.branch = test.make_branch('branch')
+    return config.BranchStack(test.branch)
+config.test_stack_builder_registry.register('branch', build_branch_stack)
+
 
 sample_long_alias="log -r-15..-1 --line"
 sample_config_text = u"""
@@ -1938,8 +1927,8 @@
 
 class TestReadonlyStore(TestStore):
 
-    scenarios = [(key, {'get_store': builder})
-                 for key, builder in test_store_builder_registry.iteritems()]
+    scenarios = [(key, {'get_store': builder}) for key, builder
+                 in config.test_store_builder_registry.iteritems()]
 
     def setUp(self):
         super(TestReadonlyStore, self).setUp()
@@ -1978,13 +1967,12 @@
 
 class TestMutableStore(TestStore):
 
-    scenarios = [(key, {'store_id': key, 'get_store': builder})
-                 for key, builder in test_store_builder_registry.iteritems()]
+    scenarios = [(key, {'store_id': key, 'get_store': builder}) for key, builder
+                 in config.test_store_builder_registry.iteritems()]
 
     def setUp(self):
         super(TestMutableStore, self).setUp()
         self.transport = self.get_transport()
-        self.branch = self.make_branch('branch')
 
     def has_store(self, store):
         store_basename = urlutils.relative_url(self.transport.external_url(),
@@ -2120,21 +2108,24 @@
 
 class TestConcurrentStoreUpdates(TestStore):
 
-    scenarios = [(key, {'get_stack': builder})
-                 for key, builder
-                 in test_compatible_stack_builder_registry.iteritems()]
+    scenarios = [(key, {'get_stack': builder}) for key, builder
+                 in config.test_stack_builder_registry.iteritems()]
 
     def setUp(self):
         super(TestConcurrentStoreUpdates, self).setUp()
         self._content = 'one=1\ntwo=2\n'
         self.stack = self.get_stack(self)
+        if not isinstance(self.stack, config._CompatibleStack):
+            raise tests.TestNotApplicable(
+                '%s is not meant to be compatible with the old config design'
+                % (self.stack,))
         self.stack.store._load_from_string(self._content)
         # Flush the store
         self.stack.store.save()
 
     def test_simple_read_access(self):
         self.assertEquals('1', self.stack.get('one'))
-    
+
     def test_simple_write_access(self):
         self.stack.set('one', 'one')
         self.assertEquals('one', self.stack.get('one'))
@@ -2366,18 +2357,12 @@
 
 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')
+    scenarios = [(key, {'get_stack': builder}) for key, builder
+                 in config.test_stack_builder_registry.iteritems()]
 
 
 class TestStackSet(TestStackWithTransport):
 
-    scenarios = [(key, {'get_stack': builder})
-                 for key, builder in test_stack_builder_registry.iteritems()]
-
     def test_simple_set(self):
         conf = self.get_stack(self)
         conf.store._load_from_string('foo=bar')
@@ -2394,9 +2379,6 @@
 
 class TestStackRemove(TestStackWithTransport):
 
-    scenarios = [(key, {'get_stack': builder})
-                 for key, builder in test_stack_builder_registry.iteritems()]
-
     def test_remove_existing(self):
         conf = self.get_stack(self)
         conf.store._load_from_string('foo=bar')
@@ -2412,9 +2394,6 @@
 
 class TestConcreteStacks(TestStackWithTransport):
 
-    scenarios = [(key, {'get_stack': builder})
-                 for key, builder in test_stack_builder_registry.iteritems()]
-
     def test_build_stack(self):
         stack = self.get_stack(self)
 



More information about the bazaar-commits mailing list