Add test_import_error_message_contains_complete_class_path test for get_class
This commit is contained in:
parent
059f96814d
commit
e4bdacbb61
@ -24,7 +24,10 @@ def get_class(name):
|
||||
module_name = name[:name.rindex('.')]
|
||||
class_name = name[name.rindex('.') + 1:]
|
||||
logger.debug('Loading: %s', name)
|
||||
module = import_module(module_name)
|
||||
try:
|
||||
module = import_module(module_name)
|
||||
except ImportError:
|
||||
raise ImportError("Couldn't load: %s" % name)
|
||||
class_object = getattr(module, class_name)
|
||||
return class_object
|
||||
|
||||
|
||||
@ -16,6 +16,12 @@ class GetClassTest(unittest.TestCase):
|
||||
test = lambda: get_class('foo.bar.Baz')
|
||||
self.assertRaises(ImportError, test)
|
||||
|
||||
def test_import_error_message_contains_complete_class_path(self):
|
||||
try:
|
||||
get_class('foo.bar.Baz')
|
||||
except ImportError as e:
|
||||
self.assert_('foo.bar.Baz' in str(e))
|
||||
|
||||
def test_loading_existing_class(self):
|
||||
cls = get_class('unittest.TestCase')
|
||||
self.assertEqual(cls.__name__, 'TestCase')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user