-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #372 from jodal/feature/add-extension-superclass
Add extension superclass and exception
- Loading branch information
Showing
5 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_classes(self): | ||
return [] | ||
|
||
def get_backend_classes(self): | ||
return [] | ||
|
||
def register_gstreamer_elements(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_classes_returns_an_empty_list(self): | ||
self.assertListEqual(self.ext.get_frontend_classes(), []) | ||
|
||
def test_get_backend_classes_returns_an_empty_list(self): | ||
self.assertListEqual(self.ext.get_backend_classes(), []) | ||
|
||
def test_register_gstreamer_elements_does_nothing_by_default(self): | ||
self.assertIsNone(self.ext.register_gstreamer_elements()) |