config: Improve handling of Deprecated config values

This commit is contained in:
Thomas Adamcik 2013-12-04 21:09:04 +01:00
parent 26ec956a08
commit da63942b48
3 changed files with 7 additions and 6 deletions

View File

@ -167,6 +167,8 @@ def _format(config, comments, schemas, display, disable):
continue
output.append(b'[%s]' % bytes(schema.name))
for key, value in serialized.items():
if isinstance(value, types.DeprecatedValue):
continue
comment = bytes(comments.get(schema.name, {}).get(key, ''))
output.append(b'%s =' % bytes(key))
if value is not None:

View File

@ -71,11 +71,11 @@ class ConfigSchema(collections.OrderedDict):
errors[key] = str(e)
for key in self.keys():
if key not in result and key not in errors:
if isinstance(self[key], types.Deprecated):
result.pop(key, None)
elif key not in result and key not in errors:
result[key] = None
errors[key] = 'config key not found.'
if isinstance(result[key], types.DeprecatedValue):
del result[key]
return result, errors

View File

@ -77,11 +77,10 @@ class ConfigSchemaTest(unittest.TestCase):
self.assertIsNone(result['bar'])
self.assertIsNone(result['baz'])
def test_deserialize_none_value(self):
self.schema['foo'].deserialize.return_value = types.DeprecatedValue()
def test_deserialize_deprecated_value(self):
self.schema['foo'] = types.Deprecated()
result, errors = self.schema.deserialize(self.values)
print result, errors
self.assertItemsEqual(['bar', 'baz'], result.keys())
self.assertNotIn('foo', errors)