Rev 5803: Add tests for set hook. in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Jun 14 06:54:54 UTC 2011


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

------------------------------------------------------------
revno: 5803
revision-id: v.ladeuil+lp at free.fr-20110614065454-lw0s6n0c36w1ogjr
parent: v.ladeuil+lp at free.fr-20110613173704-webouwsshemt2r2s
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-hooks
timestamp: Tue 2011-06-14 08:54:54 +0200
message:
  Add tests for set hook.
-------------- next part --------------
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-06-13 17:37:04 +0000
+++ b/bzrlib/tests/test_config.py	2011-06-14 06:54:54 +0000
@@ -2022,8 +2022,11 @@
         self.assertSaveHook(self.branch_config)
 
 
-class TestOldConfigHooksForRemote(tests.TestCaseWithTransport,
-                                  TestOldConfigHooksMixin):
+class TestOldConfigHooksForRemote(tests.TestCaseWithTransport):
+    """Tests config hooks for remote configs.
+
+    No tests for the remove hook as this is not implemented there.
+    """
 
     def setUp(self):
         super(TestOldConfigHooksForRemote, self).setUp()
@@ -2051,6 +2054,30 @@
         conf.set_option('remotedir', 'file')
         self.assertGetHook(conf, 'file', 'remotedir')
 
+    def assertSetHook(self, conf, name, value):
+        calls = []
+        def hook(*args):
+            calls.append(args)
+        config.ConfigHooks.install_named_hook('old_set', hook, None)
+        self.assertLength(0, calls)
+        conf.set_option(value, name)
+        self.assertLength(1, calls)
+        # We can't assert the conf object below as different configs use
+        # different means to implement set_user_option and we care only about
+        # coverage here.
+        self.assertEquals((name, value), calls[0][1:])
+
+    def test_set_hook_remote_branch(self):
+        remote_branch = branch.Branch.open(self.get_url('tree'))
+        self.addCleanup(remote_branch.lock_write().unlock)
+        self.assertSetHook(remote_branch._get_config(), 'file', 'remote')
+
+    def test_set_hook_remote_bzrdir(self):
+        remote_branch = branch.Branch.open(self.get_url('tree'))
+        self.addCleanup(remote_branch.lock_write().unlock)
+        remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
+        self.assertSetHook(remote_bzrdir._get_config(), 'file', 'remotedir')
+
 
 class TestOption(tests.TestCase):
 



More information about the bazaar-commits mailing list