config: Add deprecated config value support.
This makes it possible to mark a key as deprecated, this implies it will be ignored if present, and never included in the resulting config.
This commit is contained in:
parent
121d2c782a
commit
26ec956a08
@ -74,6 +74,8 @@ class ConfigSchema(collections.OrderedDict):
|
||||
if 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
|
||||
|
||||
|
||||
@ -31,6 +31,10 @@ class ExpandedPath(bytes):
|
||||
self.original = original
|
||||
|
||||
|
||||
class DeprecatedValue(object):
|
||||
pass
|
||||
|
||||
|
||||
class ConfigValue(object):
|
||||
"""Represents a config key's value and how to handle it.
|
||||
|
||||
@ -59,6 +63,20 @@ class ConfigValue(object):
|
||||
return bytes(value)
|
||||
|
||||
|
||||
class Deprecated(ConfigValue):
|
||||
"""Deprecated value
|
||||
|
||||
Used for ignoring old config values that are no longer in use, but should
|
||||
not cause the config parser to crash.
|
||||
"""
|
||||
|
||||
def deserialize(self, value):
|
||||
return DeprecatedValue()
|
||||
|
||||
def serialize(self, value, display=False):
|
||||
return DeprecatedValue()
|
||||
|
||||
|
||||
class String(ConfigValue):
|
||||
"""String value.
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ import logging
|
||||
import mock
|
||||
import unittest
|
||||
|
||||
from mopidy.config import schemas
|
||||
from mopidy.config import schemas, types
|
||||
|
||||
from tests import any_unicode
|
||||
|
||||
@ -77,6 +77,14 @@ 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()
|
||||
|
||||
result, errors = self.schema.deserialize(self.values)
|
||||
print result, errors
|
||||
self.assertItemsEqual(['bar', 'baz'], result.keys())
|
||||
self.assertNotIn('foo', errors)
|
||||
|
||||
|
||||
class LogLevelConfigSchemaTest(unittest.TestCase):
|
||||
def test_conversion(self):
|
||||
|
||||
@ -33,6 +33,16 @@ class ConfigValueTest(unittest.TestCase):
|
||||
self.assertIsInstance(value.serialize(object(), display=True), bytes)
|
||||
|
||||
|
||||
class DeprecatedTest(unittest.TestCase):
|
||||
def test_deserialize_returns_deprecated_value(self):
|
||||
self.assertIsInstance(types.Deprecated().deserialize(b'foobar'),
|
||||
types.DeprecatedValue)
|
||||
|
||||
def test_serialize_returns_deprecated_value(self):
|
||||
self.assertIsInstance(types.Deprecated().serialize('foobar'),
|
||||
types.DeprecatedValue)
|
||||
|
||||
|
||||
class StringTest(unittest.TestCase):
|
||||
def test_deserialize_conversion_success(self):
|
||||
value = types.String()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user