Rev 5361: Allows tests to save the config file at build time. in file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Jul 21 18:43:02 BST 2010
At file:///home/vila/src/bzr/bugs/525571-lock-bazaar-conf-files/
------------------------------------------------------------
revno: 5361
revision-id: v.ladeuil+lp at free.fr-20100721174302-g9rsvkujz2vn6fp3
parent: v.ladeuil+lp at free.fr-20100721173103-hi5qmjelkza6nm12
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: further-cleanups
timestamp: Wed 2010-07-21 19:43:02 +0200
message:
Allows tests to save the config file at build time.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2010-07-21 15:00:09 +0000
+++ b/NEWS 2010-07-21 17:43:02 +0000
@@ -69,7 +69,9 @@
* Configuration files should now use the ``_content`` parameter in the
constructor rather than the ``file`` parameter of the ``_get_parser``
- method. The later has been deprecated. (Vincent Ladeuil)
+ method. The later has been deprecated. They can also specify
+ ``_save=True`` at build time to have the configuration file immediately
+ written to disk. (Vincent Ladeuil)
bzr 2.2rc1
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2010-07-21 16:35:14 +0000
+++ b/bzrlib/config.py 2010-07-21 17:43:02 +0000
@@ -353,13 +353,16 @@
"""A configuration policy that draws from ini files."""
def __init__(self, get_filename=symbol_versioning.DEPRECATED_PARAMETER,
- file_name=None, _content=None):
+ file_name=None, _content=None, _save=False):
"""Base class for configuration files using an ini-like syntax.
:param file_name: The configuration file path.
:param _content: For tests only, a string representing the file
content. This will be utf-8 encoded.
+
+ :param _save: For tests only, whether the file should be saved upon
+ creation.
"""
super(IniBasedConfig, self).__init__()
self.file_name = file_name
@@ -376,6 +379,10 @@
_content = StringIO(_content.encode('utf-8'))
self._content = _content
self._parser = None
+ # Some tests use in-memory configs, some other always need the config
+ # file to exist on disk.
+ if _save:
+ self._write_config_file()
def _get_parser(self, file=symbol_versioning.DEPRECATED_PARAMETER):
if self._parser is not None:
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2010-07-21 17:18:23 +0000
+++ b/bzrlib/tests/test_config.py 2010-07-21 17:43:02 +0000
@@ -402,10 +402,18 @@
' Use IniBasedConfig(_content=xxx) instead.'],
conf._get_parser, file=config_file)
+class TestIniConfigSaving(tests.TestCaseInTempDir):
+
def test_cant_save_without_a_file_name(self):
conf = config.IniBasedConfig()
self.assertRaises(AssertionError, conf._write_config_file)
+ def test_saved_with_content(self):
+ content = 'foo = bar\n'
+ conf = config.IniBasedConfig(file_name='./test.conf',
+ _content=content,_save=True)
+ self.assertFileEqual(content, 'test.conf')
+
class TestLockableConfig(tests.TestCaseInTempDir):
More information about the bazaar-commits
mailing list