Test both case where class and/or module does not exist for get_class
This commit is contained in:
parent
e4bdacbb61
commit
ec67d43fc9
@ -26,9 +26,9 @@ def get_class(name):
|
|||||||
logger.debug('Loading: %s', name)
|
logger.debug('Loading: %s', name)
|
||||||
try:
|
try:
|
||||||
module = import_module(module_name)
|
module = import_module(module_name)
|
||||||
except ImportError:
|
class_object = getattr(module, class_name)
|
||||||
|
except (ImportError, AttributeError):
|
||||||
raise ImportError("Couldn't load: %s" % name)
|
raise ImportError("Couldn't load: %s" % name)
|
||||||
class_object = getattr(module, class_name)
|
|
||||||
return class_object
|
return class_object
|
||||||
|
|
||||||
def get_or_create_folder(folder):
|
def get_or_create_folder(folder):
|
||||||
|
|||||||
@ -12,10 +12,14 @@ from mopidy.models import Track, Artist, Album
|
|||||||
from tests import SkipTest, data_folder
|
from tests import SkipTest, data_folder
|
||||||
|
|
||||||
class GetClassTest(unittest.TestCase):
|
class GetClassTest(unittest.TestCase):
|
||||||
def test_loading_class_that_does_not_exist(self):
|
def test_loading_module_that_does_not_exist(self):
|
||||||
test = lambda: get_class('foo.bar.Baz')
|
test = lambda: get_class('foo.bar.Baz')
|
||||||
self.assertRaises(ImportError, test)
|
self.assertRaises(ImportError, test)
|
||||||
|
|
||||||
|
def test_loading_class_that_does_not_exist(self):
|
||||||
|
test = lambda: get_class('unittest.FooBarBaz')
|
||||||
|
self.assertRaises(ImportError, test)
|
||||||
|
|
||||||
def test_import_error_message_contains_complete_class_path(self):
|
def test_import_error_message_contains_complete_class_path(self):
|
||||||
try:
|
try:
|
||||||
get_class('foo.bar.Baz')
|
get_class('foo.bar.Baz')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user