Add more information to error message when importing a class fails (#814)
This commit is contained in:
committed by
Johannes Linke
parent
c2c37c7c30
commit
fd36cd699c
@@ -5,6 +5,8 @@ import django.contrib.staticfiles.finders
|
||||
import django
|
||||
|
||||
import compressor.utils.staticfiles
|
||||
from compressor.exceptions import FilterError
|
||||
from compressor.utils import get_class
|
||||
|
||||
from imp import reload
|
||||
|
||||
@@ -44,3 +46,13 @@ class StaticFilesTestCase(TestCase):
|
||||
self.assertTrue(compressor.utils.staticfiles.finders is None)
|
||||
finally:
|
||||
reload(compressor.utils.staticfiles)
|
||||
|
||||
|
||||
class TestGetClass(TestCase):
|
||||
|
||||
def test_get_class_import_exception(self):
|
||||
with self.assertRaises(FilterError) as context:
|
||||
get_class('common.uglify.JsUglifySourcemapCompressor')
|
||||
|
||||
self.assertTrue(('Failed to import common.uglify.JsUglifySourcemapCompressor. '
|
||||
'ImportError is: No module named' in str(context.exception)))
|
||||
|
||||
@@ -15,8 +15,10 @@ def get_class(class_string, exception=FilterError):
|
||||
mod_name, class_name = get_mod_func(class_string)
|
||||
if class_name:
|
||||
return getattr(__import__(mod_name, {}, {}, [str('')]), class_name)
|
||||
except (ImportError, AttributeError):
|
||||
raise exception('Failed to import %s' % class_string)
|
||||
except AttributeError as e:
|
||||
raise exception('Failed to import %s. AttributeError is: %s' % (class_string, e))
|
||||
except ImportError as e:
|
||||
raise exception('Failed to import %s. ImportError is: %s' % (class_string, e))
|
||||
|
||||
raise exception("Invalid class path '%s'" % class_string)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user