Rev 4844: Implement config.get_user_option_as_list. in file:///home/vila/src/bzr/reviews/deprecation-warning-preference/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Dec 15 15:05:26 GMT 2009
At file:///home/vila/src/bzr/reviews/deprecation-warning-preference/
------------------------------------------------------------
revno: 4844
revision-id: v.ladeuil+lp at free.fr-20091215150526-5opw59co07f7uhz3
parent: ted at gould.cx-20091130225537-43vr3as3yybypm4r
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: deprecation-warning-preference
timestamp: Tue 2009-12-15 16:05:26 +0100
message:
Implement config.get_user_option_as_list.
* bzrlib/tests/test_config.py:
(TestGetConfig.test_get_user_option_as_list):
* bzrlib/config.py:
(Config.get_user_option_as_list): A typed accessor.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2009-10-31 01:43:48 +0000
+++ b/bzrlib/config.py 2009-12-15 15:05:26 +0000
@@ -190,11 +190,23 @@
"""Get a generic option as a boolean - no special process, no default.
:return None if the option doesn't exist or its value can't be
- interpreted as a boolean. Returns True or False ortherwise.
+ interpreted as a boolean. Returns True or False otherwise.
"""
s = self._get_user_option(option_name)
return ui.bool_from_string(s)
+ def get_user_option_as_list(self, option_name):
+ """Get a generic option as a list - no special process, no default.
+
+ :return None if the option doesn't exist. Returns the value as a list
+ otherwise.
+ """
+ l = self._get_user_option(option_name)
+ if isinstance(l, (str, unicode)):
+ # A single value, most probably the user forgot the final ','
+ l = [l]
+ return l
+
def gpg_signing_command(self):
"""What program should be used to sign signatures?"""
result = self._gpg_signing_command()
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2009-10-31 01:43:48 +0000
+++ b/bzrlib/tests/test_config.py 2009-12-15 15:05:26 +0000
@@ -390,7 +390,7 @@
a_true_bool = true
a_false_bool = 0
an_invalid_bool = maybe
-a_list = hmm, who knows ? # This interpreted as a list !
+a_list = hmm, who knows ? # This is interpreted as a list !
""".encode('utf-8'))
my_config = config.IniBasedConfig(None)
parser = my_config._get_parser(file=config_file)
@@ -400,6 +400,23 @@
self.assertIs(None, get_option('an_invalid_bool'))
self.assertIs(None, get_option('not_defined_in_this_config'))
+
+ def test_get_user_option_as_list(self):
+ config_file = StringIO("""
+a_list = a,b,c
+length_1 = 1,
+one_item = x
+""".encode('utf-8'))
+ my_config = config.IniBasedConfig(None)
+ parser = my_config._get_parser(file=config_file)
+ get_list = my_config.get_user_option_as_list
+ self.assertEqual(['a', 'b', 'c'], get_list('a_list'))
+ self.assertEqual(['1'], get_list('length_1'))
+ self.assertEqual('x', my_config.get_user_option('one_item'))
+ # automatically cast to list
+ self.assertEqual(['x'], get_list('one_item'))
+
+
class TestGetConfig(tests.TestCase):
def test_constructs(self):
More information about the bazaar-commits
mailing list