Rev 5758: Test and implement ConfigStack.remove. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Apr 6 09:19:28 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5758
revision-id: v.ladeuil+lp at free.fr-20110406091927-xc722o12neu8n7zp
parent: v.ladeuil+lp at free.fr-20110406091249-z935paoge1uktqoe
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-stack
timestamp: Wed 2011-04-06 11:19:27 +0200
message:
Test and implement ConfigStack.remove.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-04-06 09:12:49 +0000
+++ b/bzrlib/config.py 2011-04-06 09:19:27 +0000
@@ -2219,12 +2219,23 @@
def set(self, name, value):
"""Set a new value for the option.
- This where we guarantee that the mutable section is lazily loaded: this
- means we won't load the correspoding store before setting a value.
+ This is where we guarantee that the mutable section is lazily loaded:
+ this means we won't load the corresponding store before setting a value.
"""
section = self.get_mutable_section()
section.set(name, value)
+ def remove(self, name):
+ """Remove an existing option.
+
+ This is where we guarantee that the mutable section is lazily loaded:
+ this means we won't load the correspoding store before trying to delete
+ an option. In practice the store will often be loaded but this allows
+ catching some programming errors.
+ """
+ section = self.get_mutable_section()
+ section.remove(name)
+
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-06 09:11:48 +0000
+++ b/bzrlib/tests/test_config.py 2011-04-06 09:19:27 +0000
@@ -2084,6 +2084,28 @@
self.assertEquals, 'baz', conf.get('foo')
+class TestConfigStackRemove(tests.TestCaseWithTransport):
+
+ # FIXME: This should be parametrized for all known ConfigStack or dedicated
+ # paramerized tests created to avoid bloating -- vila 2011-04-06
+
+ def test_remove_existing(self):
+ store = config.ConfigObjStore.from_string(
+ 'foo=bar', self.get_transport(), 'test.conf')
+ conf = config.ConfigStack(
+ [store.get_sections], store.get_mutable_section)
+ self.assertEquals('bar', conf.get('foo'))
+ conf.remove('foo')
+ # Did we get it back ?
+ self.assertEquals(None, conf.get('foo'))
+
+ def test_remove_unknown(self):
+ store = config.ConfigObjStore(self.get_transport(), 'test.conf')
+ conf = config.ConfigStack(
+ [store.get_sections], store.get_mutable_section)
+ self.assertRaises(KeyError, conf.remove, 'I_do_not_exist')
+
+
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
def setUp(self):
More information about the bazaar-commits
mailing list