diff --git a/mopidy/config/schemas.py b/mopidy/config/schemas.py index a535b493..67473b88 100644 --- a/mopidy/config/schemas.py +++ b/mopidy/config/schemas.py @@ -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 diff --git a/mopidy/config/types.py b/mopidy/config/types.py index d264de30..6aeaaaa7 100644 --- a/mopidy/config/types.py +++ b/mopidy/config/types.py @@ -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. diff --git a/tests/config/schemas_test.py b/tests/config/schemas_test.py index 9da8f667..82ea159b 100644 --- a/tests/config/schemas_test.py +++ b/tests/config/schemas_test.py @@ -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): diff --git a/tests/config/types_test.py b/tests/config/types_test.py index 0df3dfb4..c4b9ec88 100644 --- a/tests/config/types_test.py +++ b/tests/config/types_test.py @@ -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()