Rev 5752: Implement and test store.save() and remove the 'save' parameter from store.from_string() as this won't scale well when adding class specific parameters. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Apr 4 13:14:27 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5752
revision-id: v.ladeuil+lp at free.fr-20110404131427-b22d3elqg8jmy9l6
parent: v.ladeuil+lp at free.fr-20110404130312-nyt1lpkuustnnqq3
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-store
timestamp: Mon 2011-04-04 15:14:27 +0200
message:
Implement and test store.save() and remove the 'save' parameter from store.from_string() as this won't scale well when adding class specific parameters.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-04-04 13:03:12 +0000
+++ b/bzrlib/config.py 2011-04-04 13:14:27 +0000
@@ -2055,7 +2055,7 @@
self._content = None
@classmethod
- def from_string(cls, str_or_unicode, transport, file_name, save=False):
+ def from_string(cls, str_or_unicode, transport, file_name):
"""Create a config store from a string.
:param str_or_unicode: A string representing the file content. This will
@@ -2064,20 +2064,14 @@
:param transport: The transport object where the config file is located.
:param file_name: The configuration file basename.
-
- :param _save: Whether the file should be saved upon creation.
"""
conf = cls(transport=transport, file_name=file_name)
- conf._create_from_string(str_or_unicode, save)
+ conf._create_from_string(str_or_unicode)
return conf
- def _create_from_string(self, str_or_unicode, save):
+ def _create_from_string(self, str_or_unicode):
# We just keep the content waiting for load() to be called when needed
self._content = StringIO(str_or_unicode.encode('utf-8'))
- # Some tests use in-memory configs, some other always need the config
- # file to exist on disk.
- if save:
- self.save()
def load(self):
"""Load the store from the associated file."""
@@ -2101,6 +2095,11 @@
raise errors.ParseConfigError(e.errors, file_path)
self.loaded = True
+ def save(self):
+ out = StringIO()
+ self._config_obj.write(out)
+ self.transport.put_bytes(self.file_name, out.getvalue())
+
class cmd_config(commands.Command):
__doc__ = """Display, set or remove a configuration option.
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-04-04 13:03:12 +0000
+++ b/bzrlib/tests/test_config.py 2011-04-04 13:14:27 +0000
@@ -1926,6 +1926,22 @@
# And the load failed
self.assertEquals(False, store.loaded)
+ def test_save_empty_succeeds(self):
+ store = self.get_store('', 'foo.conf')
+ store.load()
+ self.failIfExists('foo.conf')
+ store.save()
+ self.failUnlessExists('foo.conf')
+
+ def test_save_with_content_succeeds(self):
+ store = self.get_store('foo=bar\n', 'foo.conf')
+ store.load()
+ self.failIfExists('foo.conf')
+ store.save()
+ self.failUnlessExists('foo.conf')
+ # FIXME: Far too ConfigObj specific
+ self.assertFileEqual('foo = bar\n', 'foo.conf')
+
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
More information about the bazaar-commits
mailing list