Rev 5804: Add test for config load hook for remote configs. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Jun 14 08:59:12 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5804
revision-id: v.ladeuil+lp at free.fr-20110614085912-cmfzaeojb9f6a1ni
parent: v.ladeuil+lp at free.fr-20110614065454-lw0s6n0c36w1ogjr
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-hooks
timestamp: Tue 2011-06-14 10:59:12 +0200
message:
Add test for config load hook for remote configs.
-------------- next part --------------
=== modified file 'bzrlib/hooks.py'
--- a/bzrlib/hooks.py 2011-06-10 13:14:34 +0000
+++ b/bzrlib/hooks.py 2011-06-14 08:59:12 +0000
@@ -257,8 +257,7 @@
try:
uninstall = getattr(hook, "uninstall")
except AttributeError:
- raise errors.UnsupportedOperation(self.install_named_hook_lazy,
- self)
+ raise errors.UnsupportedOperation(self.uninstall_named_hook, self)
else:
uninstall(label)
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2011-06-13 17:24:27 +0000
+++ b/bzrlib/remote.py 2011-06-14 08:59:12 +0000
@@ -3123,7 +3123,10 @@
if len(response[0]) and response[0][0] != 'ok':
raise errors.UnexpectedSmartServerResponse(response)
lines = response[1].read_body_bytes().splitlines()
- return config.ConfigObj(lines, encoding='utf-8')
+ conf = config.ConfigObj(lines, encoding='utf-8')
+ for hook in config.ConfigHooks['old_load']:
+ hook(self)
+ return conf
class RemoteBranchConfig(RemoteConfig):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-06-14 06:54:54 +0000
+++ b/bzrlib/tests/test_config.py 2011-06-14 08:59:12 +0000
@@ -37,6 +37,7 @@
ui,
urlutils,
registry,
+ remote,
tests,
trace,
transport,
@@ -45,7 +46,7 @@
deprecated_in,
deprecated_method,
)
-from bzrlib.transport import remote
+from bzrlib.transport import remote as transport_remote
from bzrlib.tests import (
features,
scenarios,
@@ -118,7 +119,8 @@
def build_remote_branch_store(test):
# There is only one permutation (but we won't be able to handle more with
# this design anyway)
- (transport_class, server_class) = remote.get_test_permutations()[0]
+ (transport_class,
+ server_class) = transport_remote.get_test_permutations()[0]
build_backing_branch(test, 'branch', transport_class, server_class)
b = branch.Branch.open(test.get_url('branch'))
return config.BranchStore(b)
@@ -142,7 +144,8 @@
def build_remote_branch_stack(test):
# There is only one permutation (but we won't be able to handle more with
# this design anyway)
- (transport_class, server_class) = remote.get_test_permutations()[0]
+ (transport_class,
+ server_class) = transport_remote.get_test_permutations()[0]
build_backing_branch(test, 'branch', transport_class, server_class)
b = branch.Branch.open(test.get_url('branch'))
return config.BranchStack(b)
@@ -2038,6 +2041,8 @@
def hook(*args):
calls.append(args)
config.ConfigHooks.install_named_hook('old_get', hook, None)
+ self.addCleanup(
+ config.ConfigHooks.uninstall_named_hook, 'old_get', None)
self.assertLength(0, calls)
actual_value = conf.get_option(name)
self.assertEquals(value, actual_value)
@@ -2059,6 +2064,8 @@
def hook(*args):
calls.append(args)
config.ConfigHooks.install_named_hook('old_set', hook, None)
+ self.addCleanup(
+ config.ConfigHooks.uninstall_named_hook, 'old_set', None)
self.assertLength(0, calls)
conf.set_option(value, name)
self.assertLength(1, calls)
@@ -2078,6 +2085,37 @@
remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
self.assertSetHook(remote_bzrdir._get_config(), 'file', 'remotedir')
+ def assertLoadHook(self, expected_nb_calls, name, conf_class, *conf_args):
+ calls = []
+ def hook(*args):
+ self.debug()
+ calls.append(args)
+ config.ConfigHooks.install_named_hook('old_load', hook, None)
+ self.addCleanup(
+ config.ConfigHooks.uninstall_named_hook, 'old_load', None)
+ self.assertLength(0, calls)
+ # Build a config
+ conf = conf_class(*conf_args)
+ # Access an option to trigger a load
+ conf.get_option(name)
+ self.assertLength(expected_nb_calls, calls)
+ # Since we can't assert about conf, we just use the number of calls ;-/
+
+ def test_load_hook_remote_branch(self):
+ remote_branch = branch.Branch.open(self.get_url('tree'))
+ self.assertLoadHook(1, 'file', remote.RemoteBranchConfig, remote_branch)
+
+ def test_load_hook_remote_bzrdir(self):
+ remote_bzrdir = bzrdir.BzrDir.open(self.get_url('tree'))
+ # The config file doesn't exist, set an option to force its creation
+ conf = remote_bzrdir._get_config()
+ conf.set_option('remotedir', 'file')
+ # We get one call for the server and one call for the client, this is
+ # caused by the differences in implementations betwen
+ # SmartServerBzrDirRequestConfigFile (in smart/bzrdir.py) and
+ # SmartServerBranchGetConfigFile (in smart/branch.py)
+ self.assertLoadHook(2 ,'file', remote.RemoteBzrDirConfig, remote_bzrdir)
+
class TestOption(tests.TestCase):
More information about the bazaar-commits
mailing list