Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension superclass and exception #372

Merged
merged 4 commits into from
Apr 1, 2013
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions mopidy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ class SettingsError(MopidyException):

class OptionalDependencyError(MopidyException):
pass


class ExtensionError(MopidyException):
pass
27 changes: 27 additions & 0 deletions mopidy/ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import unicode_literals


class Extension(object):

name = None
version = None

def get_default_config(self):
raise NotImplementedError(
'Add at least a config section with "enabled = true"')

def validate_config(self, config):
raise NotImplementedError(
'You must explicitly pass config validation if not needed')

def validate_environment(self):
pass

def get_frontend_class(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/class/classes/ perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple frontends in a single extension? Why not. A lot more future proof.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

pass

def get_backend_class(self):
pass

def register_gstreamer_elements(self):
pass
25 changes: 25 additions & 0 deletions tests/exceptions_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import unicode_literals

from mopidy import exceptions

from tests import unittest


class ExceptionsTest(unittest.TestCase):
def test_exception_can_include_message_string(self):
exc = exceptions.MopidyException('foo')

self.assertEqual(exc.message, 'foo')
self.assertEqual(str(exc), 'foo')

def test_settings_error_is_a_mopidy_exception(self):
self.assert_(issubclass(
exceptions.SettingsError, exceptions.MopidyException))

def test_optional_dependency_error_is_a_mopidy_exception(self):
self.assert_(issubclass(
exceptions.OptionalDependencyError, exceptions.MopidyException))

def test_extension_error_is_a_mopidy_exception(self):
self.assert_(issubclass(
exceptions.ExtensionError, exceptions.MopidyException))
34 changes: 34 additions & 0 deletions tests/ext_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from __future__ import unicode_literals

from mopidy.ext import Extension

from tests import unittest


class ExtensionTest(unittest.TestCase):
def setUp(self):
self.ext = Extension()

def test_name_is_none(self):
self.assertIsNone(self.ext.name)

def test_version_is_none(self):
self.assertIsNone(self.ext.version)

def test_get_default_config_raises_not_implemented(self):
self.assertRaises(NotImplementedError, self.ext.get_default_config)

def test_validate_config_raises_not_implemented(self):
self.assertRaises(NotImplementedError, self.ext.validate_config, None)

def test_validate_environment_does_nothing_by_default(self):
self.assertIsNone(self.ext.validate_environment())

def test_get_frontend_class_returns_none_by_default(self):
self.assertIsNone(self.ext.get_frontend_class())

def test_get_backend_class_returns_none_by_default(self):
self.assertIsNone(self.ext.get_backend_class())

def test_register_gstreamer_elements_does_nothing_by_default(self):
self.assertIsNone(self.ext.register_gstreamer_elements())