diff --git a/mopidy/utils/config.py b/mopidy/utils/config.py index e96d3d29..d7eed6bf 100644 --- a/mopidy/utils/config.py +++ b/mopidy/utils/config.py @@ -209,3 +209,17 @@ class ConfigSchema(object): if errors: raise exceptions.ConfigError(errors) return values + + +class ExtensionConfigSchema(ConfigSchema): + """Sub-classed ConfigSchema for use in extensions. + + Ensures that `enabled` config value is present and that section name is + prefixed with ext. + """ + def __init__(self): + super(ExtensionConfigSchema, self).__init__() + self['enabled'] = Boolean() + + def format(self, name, values): + return super(ExtensionConfigSchema, self).format('ext.%s' % name, values) diff --git a/tests/utils/config_test.py b/tests/utils/config_test.py index b5052bae..ae4f4a02 100644 --- a/tests/utils/config_test.py +++ b/tests/utils/config_test.py @@ -320,3 +320,13 @@ class ConfigSchemaTest(unittest.TestCase): self.assertNotIn('foo', cm.exception) self.assertIn('failure', cm.exception['bar']) self.assertIn('not found', cm.exception['baz']) + + +class ExtensionConfigSchemaTest(unittest.TestCase): + def test_schema_includes_enabled(self): + schema = config.ExtensionConfigSchema() + self.assertIsInstance(schema['enabled'], config.Boolean) + + def test_section_name_is_prefixed(self): + schema = config.ExtensionConfigSchema() + self.assertEqual('[ext.foo]', schema.format('foo', {}))