From 837fb00fb7157ef789eb54b7729a8bc1b5196902 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 3 Aug 2014 23:13:12 +0200 Subject: [PATCH] Fail early if extension doesn't implement setup() Fixes #813 --- docs/changelog.rst | 4 ++++ mopidy/ext.py | 2 +- tests/test_ext.py | 7 ++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index c5bc83f8..277c79ed 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -20,6 +20,10 @@ Bug fix release. - Zeroconf: Fix intermittent DBus/Avahi exception. +- Extensions: Fail early if trying to setup an extension which doesn't + implement the :meth:`mopidy.ext.Extension.setup` method. (Fixes: + :issue:`813`) + v0.19.2 (2014-07-26) ==================== diff --git a/mopidy/ext.py b/mopidy/ext.py index d259b686..3f375a69 100644 --- a/mopidy/ext.py +++ b/mopidy/ext.py @@ -99,7 +99,7 @@ class Extension(object): :param registry: the extension registry :type registry: :class:`Registry` """ - pass + raise NotImplementedError class Registry(collections.Mapping): diff --git a/tests/test_ext.py b/tests/test_ext.py index 5338c91d..428f3712 100644 --- a/tests/test_ext.py +++ b/tests/test_ext.py @@ -19,7 +19,8 @@ class ExtensionTest(unittest.TestCase): self.assertIsNone(self.ext.version) def test_get_default_config_raises_not_implemented(self): - self.assertRaises(NotImplementedError, self.ext.get_default_config) + with self.assertRaises(NotImplementedError): + self.ext.get_default_config() def test_get_config_schema_returns_extension_schema(self): schema = self.ext.get_config_schema() @@ -27,3 +28,7 @@ class ExtensionTest(unittest.TestCase): def test_validate_environment_does_nothing_by_default(self): self.assertIsNone(self.ext.validate_environment()) + + def test_setup_raises_not_implemented(self): + with self.assertRaises(NotImplementedError): + self.ext.setup(None)