[Zope3-checkins] SVN: Zope3/trunk/ zope.configuration doesn't hide
import errors inside python modules
Florent Guillaume
fg at nuxeo.com
Sun Dec 4 16:26:50 EST 2005
Log message for revision 40527:
zope.configuration doesn't hide import errors inside python modules
anymore.
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/configuration/config.py
U Zope3/trunk/src/zope/configuration/tests/test_config.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-12-04 21:17:18 UTC (rev 40526)
+++ Zope3/trunk/doc/CHANGES.txt 2005-12-04 21:26:50 UTC (rev 40527)
@@ -162,6 +162,9 @@
Bug Fixes
+ - zope.configuration doesn't hide import errors inside python
+ modules anymore.
+
- Fixed Bug 484: Viewmeta directive bug. The browser:view and page:view
directives did not apply the 'allowed_attributes' attribute and the
unit test checking this was broken because the 'attribute' will always
Modified: Zope3/trunk/src/zope/configuration/config.py
===================================================================
--- Zope3/trunk/src/zope/configuration/config.py 2005-12-04 21:17:18 UTC (rev 40526)
+++ Zope3/trunk/src/zope/configuration/config.py 2005-12-04 21:26:50 UTC (rev 40527)
@@ -183,8 +183,11 @@
try:
mod = __import__(mname, *_import_chickens)
except ImportError, v:
+ if sys.exc_info()[2].tb_next is not None:
+ # ImportError was caused deeper
+ raise
raise ConfigurationError(
- "Couldn't import %s, %s" % (mname, v)), None, sys.exc_info()[2]
+ "ImportError: Couldn't import %s, %s" % (mname, v))
if not oname:
# see not mname case above
@@ -202,22 +205,9 @@
try:
return __import__(mname+'.'+oname, *_import_chickens)
except ImportError:
-
- # We need to try to figure out what module the import
- # error is complaining about. If the import failed
- # due to a failure to import some other module
- # imported by the module we are importing, we want to
- # know it. Unfortunately, the value of the import
- # error is just a string error message. :( We can't
- # pull it apart directly to see what module couldn't
- # be imported. The only thing we can really do is to
- # try to "screen scrape" the error message:
-
- if str(sys.exc_info()[1]).find(oname) < 0:
- # There seems to have been an error further down,
- # so reraise the exception so as not to hide it.
+ if sys.exc_info()[2].tb_next is not None:
+ # ImportError was caused deeper
raise
-
raise ConfigurationError(
"ImportError: Module %s has no global %s" % (mname, oname))
Modified: Zope3/trunk/src/zope/configuration/tests/test_config.py
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/test_config.py 2005-12-04 21:17:18 UTC (rev 40526)
+++ Zope3/trunk/src/zope/configuration/tests/test_config.py 2005-12-04 21:26:50 UTC (rev 40527)
@@ -261,17 +261,46 @@
ValueError: The given name is blank
"""
-def test_bad_import():
+def test_bad_dotted_last_import():
"""
+ >>> c = config.ConfigurationContext()
+ Import error caused by a bad last component in the dotted name.
+
+ >>> c.resolve('zope.configuration.tests.nosuch')
+ Traceback (most recent call last):
+ ...
+ ConfigurationError: ImportError: Module zope.configuration.tests""" \
+ """ has no global nosuch
+ """
+
+def test_bad_dotted_import():
+ """
>>> c = config.ConfigurationContext()
- >>> c.resolve('zope.configuration.tests.victim.x')
+ Import error caused by a totally wrong dotted name.
+
+ >>> c.resolve('zope.configuration.nosuch.noreally')
Traceback (most recent call last):
...
- ConfigurationError: Couldn't import zope.configuration.tests.victim,""" \
- """ No module named bad_to_the_bone
+ ConfigurationError: ImportError: Couldn't import""" \
+ """ zope.configuration.nosuch, No module named nosuch
+ """
+def test_bad_sub_last_import():
+ """
+ >>> c = config.ConfigurationContext()
+
+ Import error caused by a bad sub import inside the referenced
+ dotted name. Here we keep the standard traceback.
+
+ >>> c.resolve('zope.configuration.tests.victim')
+ Traceback (most recent call last):
+ ...
+ File "...bad.py", line 3 in ?
+ import bad_to_the_bone
+ ImportError: No module named bad_to_the_bone
+
Cleanup:
>>> for name in ('zope.configuration.tests.victim',
@@ -280,6 +309,28 @@
... del sys.modules[name]
"""
+def test_bad_sub_import():
+ """
+ >>> c = config.ConfigurationContext()
+
+ Import error caused by a bad sub import inside part of the referenced
+ dotted name. Here we keep the standard traceback.
+
+ >>> c.resolve('zope.configuration.tests.victim.nosuch')
+ Traceback (most recent call last):
+ ...
+ File "...bad.py", line 3 in ?
+ import bad_to_the_bone
+ ImportError: No module named bad_to_the_bone
+
+ Cleanup:
+
+ >>> for name in ('zope.configuration.tests.victim',
+ ... 'zope.configuration.tests.bad'):
+ ... if name in sys.modules:
+ ... del sys.modules[name]
+ """
+
def test_suite():
return unittest.TestSuite((
DocTestSuite('zope.configuration.fields'),
More information about the Zope3-Checkins
mailing list