Add boolean as a get_value argument

This commit is contained in:
Stefano Rivera 2010-12-21 01:51:10 +02:00
parent 0ad5bd5174
commit 2c1e1c8727
3 changed files with 14 additions and 9 deletions

View File

@ -59,8 +59,8 @@ This specifies the preferred test\-builder, one of
.TP
.B UBUNTUTOOLS_UPDATE_BUILDER
Boolean. Whether or not to update the test\-builder before each test
build.
Whether or not to update the test\-builder before each test build.
.RB "One of " yes " or " no " (default).
.TP
.B UBUNTUTOOLS_LPINSTANCE

View File

@ -67,7 +67,7 @@ class UDTConfig(object):
f.close()
return config
def get_value(self, key, default=None, compat_keys=[]):
def get_value(self, key, default=None, boolean=False, compat_keys=[]):
"""Retrieve a value from the environment or configuration files.
keys are prefixed with the script name, falling back to UBUNTUTOOLS for
package-wide keys.
@ -90,8 +90,11 @@ class UDTConfig(object):
for store in (os.environ, self.config):
if k in store:
value = store[k]
if value in ('yes', 'no'):
value = value == 'yes'
if boolean:
if value in ('yes', 'no'):
value = value == 'yes'
else:
continue
return value
return default

View File

@ -83,9 +83,9 @@ REPEAT=yes
'REPEAT': 'yes',
})
def get_value(self, key, default=None, compat_keys=[]):
def get_value(self, *args, **kwargs):
config = UDTConfig(prefix='TEST')
return config.get_value(key, default=default, compat_keys=compat_keys)
return config.get_value(*args, **kwargs)
def test_defaults(self):
self.assertEqual(self.get_value('BUILDER'), 'pbuilder')
@ -120,9 +120,11 @@ REPEAT=yes
def test_boolean(self):
config_files['user'] = "TEST_BOOLEAN=yes"
self.assertEqual(self.get_value('BOOLEAN'), True)
self.assertEqual(self.get_value('BOOLEAN', boolean=True), True)
config_files['user'] = "TEST_BOOLEAN=no"
self.assertEqual(self.get_value('BOOLEAN'), False)
self.assertEqual(self.get_value('BOOLEAN', boolean=True), False)
config_files['user'] = "TEST_BOOLEAN=true"
self.assertEqual(self.get_value('BOOLEAN', boolean=True), None)
def test_nonpackagewide(self):
config_files['user'] = 'UBUNTUTOOLS_FOOBAR=a'