Rev 5353: Make the test_listen_to_the_last_speaker pass and fix fallouts. in file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Jul 21 17:17:27 BST 2010
At file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
------------------------------------------------------------
revno: 5353
revision-id: v.ladeuil+lp at free.fr-20100721161727-agtcf9n5r8wmvahr
parent: v.ladeuil+lp at free.fr-20100721152021-mx5m24ewdclytsrj
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: lockable-config-files
timestamp: Wed 2010-07-21 18:17:27 +0200
message:
Make the test_listen_to_the_last_speaker pass and fix fallouts.
* bzrlib/tests/test_config.py:
(InstrumentedConfigObj): Add reload.
(TestLockableConfig): Start adding tests for concurrent accesses.
(TestLocationConfig.test_set_user_setting_sets_and_saves): Add
'reload' to the calls list.
* bzrlib/config.py:
(IniBasedConfig.__init__): Simplified.
(IniBasedConfig._get_parser): Make sure the parser file name is
set.
(GlobalConfig._set_option, LocationConfig.set_user_option):
Refresh the parser if needed.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-07-19 13:09:01 +0000
+++ b/bzrlib/config.py 2010-07-21 16:17:27 +0000
@@ -362,20 +362,15 @@
content. This will be utf-8 encoded.
"""
super(IniBasedConfig, self).__init__()
+ self.file_name = file_name
if symbol_versioning.deprecated_passed(get_filename):
symbol_versioning.warn(
'IniBasedConfig.__init__(get_filename) was deprecated in 2.3.'
' Use file_name instead.',
DeprecationWarning,
stacklevel=2)
- if get_filename is None:
- # Tests use in-memory config files that doesn't need to be
- # saved on disk
- self.file_name = None
- else:
+ if get_filename is not None:
self.file_name = get_filename()
- else:
- self.file_name = file_name
if _content is not None:
# wrap the content as a file-like object
_content = StringIO(_content.encode('utf-8'))
@@ -401,6 +396,8 @@
self._parser = ConfigObj(co_input, encoding='utf-8')
except configobj.ConfigObjError, e:
raise errors.ParseConfigError(e.errors, e.config.filename)
+ # Make sure self._parser.reload() will use the right file name
+ self._parser.filename = self.file_name
return self._parser
def _get_matching_sections(self):
@@ -558,6 +555,8 @@
# file lock on bazaar.conf.
conf_dir = os.path.dirname(self.file_name)
ensure_config_dir_exists(conf_dir)
+ if self._parser is not None:
+ self._parser.reload()
self._get_parser().setdefault(section, {})[option] = value
self._write_config_file()
@@ -676,6 +675,8 @@
STORE_LOCATION_APPENDPATH]:
raise ValueError('bad storage policy %r for %r' %
(store, option))
+ if self._parser is not None:
+ self._parser.reload()
# FIXME: RBC 20051029 This should refresh the parser and also take a
# file lock on locations.conf.
conf_dir = os.path.dirname(self.file_name)
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-07-21 15:20:21 +0000
+++ b/bzrlib/tests/test_config.py 2010-07-21 16:17:27 +0000
@@ -129,6 +129,9 @@
self._calls.append(('keys',))
return []
+ def reload(self):
+ self._calls.append(('reload',))
+
def write(self, arg):
self._calls.append(('write',))
@@ -426,6 +429,16 @@
self.config.set_user_option('one', 'one')
self.assertEquals('one', self.config.get_user_option('one'))
+ def test_listen_to_the_last_speaker(self):
+ c1 = self.config
+ c2 = self.create_config(self._content)
+ c1.set_user_option('one', 'ONE')
+ c2.set_user_option('two', 'TWO')
+ self.assertEquals('ONE', c1.get_user_option('one'))
+ self.assertEquals('TWO', c2.get_user_option('two'))
+ # The second update respect the first one
+ self.assertEquals('ONE', c2.get_user_option('one'))
+
class TestGetUserOptionAs(TestIniConfig):
@@ -1020,7 +1033,8 @@
'converted to use policies.'],
self.my_config.set_user_option,
'foo', 'bar', store=config.STORE_LOCATION)
- self.assertEqual([('__contains__', '/a/c'),
+ self.assertEqual([('reload',),
+ ('__contains__', '/a/c'),
('__contains__', '/a/c/'),
('__setitem__', '/a/c', {}),
('__getitem__', '/a/c'),
More information about the bazaar-commits
mailing list