Rev 5750: Simple set implementation. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Apr 5 15:26:46 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5750
revision-id: v.ladeuil+lp at free.fr-20110405152646-6ddal7js46vebqx7
parent: v.ladeuil+lp at free.fr-20110405150855-kdf5y64v39qzrmbi
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-stack
timestamp: Tue 2011-04-05 17:26:46 +0200
message:
Simple set implementation.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-04-05 15:08:55 +0000
+++ b/bzrlib/config.py 2011-04-05 15:26:46 +0000
@@ -2168,22 +2168,27 @@
class ConfigStack(object):
"""A stack of configurations where an option can be defined"""
- def __init__(self, config_list):
+ def __init__(self, config_list, store=None):
self.list = config_list
for c in self.list:
# Sanity check
if not hasattr(c, 'get'):
raise AssertionError("%r does not provide a 'get' method"
% (c,))
+ self.store = store
def get(self, name):
"""Return the value from the first definition found in the list"""
+ value = None
for c in self.list:
value = c.get(name)
if value is not None:
break
return value
+ def set(self, name, value):
+ self.store.set_option(name, value)
+
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-05 15:08:55 +0000
+++ b/bzrlib/tests/test_config.py 2011-04-05 15:26:46 +0000
@@ -2049,6 +2049,21 @@
self.assertEquals('baz', conf_stack.get('foo'))
+class TestConfigStackSet(tests.TestCaseWithTransport):
+
+ # FIXME: This should be parametrized for all known ConfigStack or dedicated
+ # paramerized tests created to avoid bloating -- vila 2011-04-05
+
+ def test_simple_set(self):
+ store = config.ConfigObjStore.from_string(
+ 'foo=bar', self.get_transport(), 'test.conf')
+ conf = config.ConfigStack(list(store.get_sections()), store)
+ self.assertEquals('bar', conf.get('foo'))
+ conf.set('foo', 'baz')
+ # Did we get it back ?
+ self.assertEquals('baz', conf.get('foo'))
+
+
class TestConfigGetOptions(tests.TestCaseWithTransport, TestOptionsMixin):
def setUp(self):
More information about the bazaar-commits
mailing list