Script-specific variables win over package variables no matter which store they come from

This commit is contained in:
Stefano Rivera 2010-12-21 00:28:31 +02:00
parent 4336f7442a
commit 4f7a5232a2
2 changed files with 9 additions and 10 deletions

View File

@ -70,8 +70,8 @@ class UDTConfig(object):
keys are prefixed with the script name, falling back to UBUNTUTOOLS for
package-wide keys.
Store Priority: Environment variables, user conf, system conf
Variable Priority: PREFIX_KEY, UBUNTUTOOLS_KEY, compat_keys
Store Priority: Environment variables, user conf, system conf
Historical variable names can be supplied via compat_keys, no prefix is
applied to them.
@ -84,8 +84,8 @@ class UDTConfig(object):
keys.append('UBUNTUTOOLS_' + key)
keys += compat_keys
for store in (os.environ, self.config):
for k in keys:
for k in keys:
for store in (os.environ, self.config):
if k in store:
value = store[k]
if value in ('yes', 'no'):

View File

@ -108,16 +108,15 @@ REPEAT=yes
os.environ['UBUNTUTOOLS_BUILDER'] = 'baz'
self.assertEqual(self.get_value('BUILDER'), 'baz')
def test_any_environment_precedence(self):
def test_general_environment_specific_config_precedence(self):
config_files['user'] = "TEST_BUILDER=bar"
os.environ['UBUNTUTOOLS_BUILDER'] = 'foo'
self.assertEqual(self.get_value('BUILDER'), 'foo')
self.assertEqual(self.get_value('BUILDER'), 'bar')
def test_compat_environment_precedence(self):
config_files['user'] = "TEST_BUILDER=bar"
os.environ['BUILDER'] = 'baz'
self.assertEqual(self.get_value('BUILDER', compat_keys=['BUILDER']),
'baz')
def test_compat_keys(self):
config_files['user'] = 'COMPATFOOBAR=bar'
self.assertEqual(self.get_value('QUX', compat_keys=['COMPATFOOBAR']),
'bar')
def test_boolean(self):
config_files['user'] = "TEST_BOOLEAN=yes"