Mercurial > hg
changeset 2502:18cf95ad3666
Allow using default values with ui.configlist, too, and add a test for this.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Mon, 26 Jun 2006 22:44:48 +0200 |
parents | b73552a00b20 |
children | 37655f10ced6 158d3d2ae070 |
files | mercurial/ui.py tests/test-ui-config tests/test-ui-config.out |
diffstat | 3 files changed, 80 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/ui.py Mon Jun 26 16:47:24 2006 +0200 +++ b/mercurial/ui.py Mon Jun 26 22:44:48 2006 +0200 @@ -99,10 +99,10 @@ """Return a list of comma/space separated strings""" result = self.config(section, name) if result is None: - return [] - else: - return result.replace(",", " ").split() - + result = default or [] + if isinstance(result, basestring): + result = result.replace(",", " ").split() + return result def configbool(self, section, name, default=False): if self.overlay.has_key((section, name)):
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-ui-config Mon Jun 26 22:44:48 2006 +0200 @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +from mercurial import ui + +testui = ui.ui() +testui.updateopts(config=[ + 'values.string=string value', + 'values.bool1=true', + 'values.bool2=false', + 'lists.list1=foo', + 'lists.list2=foo bar baz', + 'lists.list3=alice, bob', + 'lists.list4=foo bar baz alice, bob', +]) + +print repr(testui.configitems('values')) +print repr(testui.configitems('lists')) +print "---" +print repr(testui.config('values', 'string')) +print repr(testui.config('values', 'bool1')) +print repr(testui.config('values', 'bool2')) +print repr(testui.config('values', 'unknown')) +print "---" +try: + print repr(testui.configbool('values', 'string')) +except ValueError, why: + print why +print repr(testui.configbool('values', 'bool1')) +print repr(testui.configbool('values', 'bool2')) +print repr(testui.configbool('values', 'bool2', True)) +print repr(testui.configbool('values', 'unknown')) +print repr(testui.configbool('values', 'unknown', True)) +print "---" +print repr(testui.configlist('lists', 'list1')) +print repr(testui.configlist('lists', 'list2')) +print repr(testui.configlist('lists', 'list3')) +print repr(testui.configlist('lists', 'list4')) +print repr(testui.configlist('lists', 'list4', ['foo'])) +print repr(testui.configlist('lists', 'unknown')) +print repr(testui.configlist('lists', 'unknown', '')) +print repr(testui.configlist('lists', 'unknown', 'foo')) +print repr(testui.configlist('lists', 'unknown', ['foo'])) +print repr(testui.configlist('lists', 'unknown', 'foo bar')) +print repr(testui.configlist('lists', 'unknown', 'foo, bar')) +print repr(testui.configlist('lists', 'unknown', ['foo bar'])) +print repr(testui.configlist('lists', 'unknown', ['foo', 'bar'])) +print "---"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-ui-config.out Mon Jun 26 22:44:48 2006 +0200 @@ -0,0 +1,29 @@ +[('bool1', 'true'), ('bool2', 'false'), ('string', 'string value')] +[('list1', 'foo'), ('list2', 'foo bar baz'), ('list3', 'alice, bob'), ('list4', 'foo bar baz alice, bob')] +--- +'string value' +'true' +'false' +None +--- +Not a boolean: string value +True +False +False +False +True +--- +['foo'] +['foo', 'bar', 'baz'] +['alice', 'bob'] +['foo', 'bar', 'baz', 'alice', 'bob'] +['foo', 'bar', 'baz', 'alice', 'bob'] +[] +[] +['foo'] +['foo'] +['foo', 'bar'] +['foo', 'bar'] +['foo bar'] +['foo', 'bar'] +---