Rev 5800: Add config old_get hook for remote config. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Jun 13 17:24:27 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5800
revision-id: v.ladeuil+lp at free.fr-20110613172427-j62b8nvgauq90tdy
parent: v.ladeuil+lp at free.fr-20110613162745-s081jt019glzvsp2
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-hooks
timestamp: Mon 2011-06-13 19:24:27 +0200
message:
Add config old_get hook for remote config.
-------------- next part --------------
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2011-05-20 13:28:35 +0000
+++ b/bzrlib/remote.py 2011-06-13 17:24:27 +0000
@@ -3101,16 +3101,23 @@
"""
try:
configobj = self._get_configobj()
+ section_obj = None
if section is None:
section_obj = configobj
else:
try:
section_obj = configobj[section]
except KeyError:
- return default
- return section_obj.get(name, default)
+ pass
+ if section_obj is None:
+ value = default
+ else:
+ value = section_obj.get(name, default)
except errors.UnknownSmartMethod:
- return self._vfs_get_option(name, section, default)
+ value = self._vfs_get_option(name, section, default)
+ for hook in config.ConfigHooks['old_get']:
+ hook(self, name, value)
+ return value
def _response_to_configobj(self, response):
if len(response[0]) and response[0][0] != 'ok':
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-06-13 16:27:45 +0000
+++ b/bzrlib/tests/test_config.py 2011-06-13 17:24:27 +0000
@@ -48,8 +48,8 @@
from bzrlib.transport import remote
from bzrlib.tests import (
features,
- TestSkipped,
scenarios,
+ test_server,
)
from bzrlib.util.configobj import configobj
@@ -2025,6 +2025,29 @@
self.assertSaveHook(self.branch_config)
+class TestOldConfigHooksForRemote(tests.TestCaseWithTransport,
+ TestOldConfigHooksMixin):
+
+ def setUp(self):
+ super(TestOldConfigHooksForRemote, self).setUp()
+ self.transport_server = test_server.SmartTCPServer_for_testing
+ create_configs_with_file_option(self)
+
+ def test_get_hook(self):
+ remote_branch = branch.Branch.open(self.get_url('tree'))
+ conf = remote_branch._get_config()
+ calls = []
+ def hook(*args):
+ calls.append(args)
+ config.ConfigHooks.install_named_hook('old_get', hook, None)
+ self.assertLength(0, calls)
+ actual_value = conf.get_option('file')
+ self.assertEquals('branch', actual_value)
+ self.assertLength(1, calls)
+ self.assertEquals((conf, 'file', 'branch'), calls[0])
+
+
+
class TestOption(tests.TestCase):
def test_default_value(self):
@@ -3404,7 +3427,8 @@
to be able to choose a user name with no configuration.
"""
if sys.platform == 'win32':
- raise TestSkipped("User name inference not implemented on win32")
+ raise tests.TestSkipped(
+ "User name inference not implemented on win32")
realname, address = config._auto_user_id()
if os.path.exists('/etc/mailname'):
self.assertIsNot(None, realname)
More information about the bazaar-commits
mailing list