utils: Remove unused importing utils
This commit is contained in:
parent
0b1f51f9e8
commit
f38b806133
@ -1,26 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
|
||||
logger = logging.getLogger('mopidy.utils')
|
||||
|
||||
|
||||
def import_module(name):
|
||||
__import__(name)
|
||||
return sys.modules[name]
|
||||
|
||||
|
||||
def get_class(name):
|
||||
logger.debug('Loading: %s', name)
|
||||
if '.' not in name:
|
||||
raise ImportError("Couldn't load: %s" % name)
|
||||
module_name = name[:name.rindex('.')]
|
||||
cls_name = name[name.rindex('.') + 1:]
|
||||
try:
|
||||
module = import_module(module_name)
|
||||
cls = getattr(module, cls_name)
|
||||
except (ImportError, AttributeError):
|
||||
raise ImportError("Couldn't load: %s" % name)
|
||||
return cls
|
||||
@ -1,29 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from mopidy.utils import importing
|
||||
|
||||
from tests import unittest
|
||||
|
||||
|
||||
class GetClassTest(unittest.TestCase):
|
||||
def test_loading_module_that_does_not_exist(self):
|
||||
with self.assertRaises(ImportError):
|
||||
importing.get_class('foo.bar.Baz')
|
||||
|
||||
def test_loading_class_that_does_not_exist(self):
|
||||
with self.assertRaises(ImportError):
|
||||
importing.get_class('unittest.FooBarBaz')
|
||||
|
||||
def test_loading_incorrect_class_path(self):
|
||||
with self.assertRaises(ImportError):
|
||||
importing.get_class('foobarbaz')
|
||||
|
||||
def test_import_error_message_contains_complete_class_path(self):
|
||||
try:
|
||||
importing.get_class('foo.bar.Baz')
|
||||
except ImportError as e:
|
||||
self.assertIn('foo.bar.Baz', str(e))
|
||||
|
||||
def test_loading_existing_class(self):
|
||||
cls = importing.get_class('unittest.TestCase')
|
||||
self.assertEqual(cls.__name__, 'TestCase')
|
||||
Loading…
Reference in New Issue
Block a user