[Zope-Checkins] SVN: Zope/trunk/src/DocumentTemplate/ LP #372629: fix <dtml-raise> for zExceptions.

Tres Seaver tseaver at palladion.com
Wed May 6 12:19:57 EDT 2009


Log message for revision 99792:
  LP #372629:  fix <dtml-raise> for zExceptions.

Changed:
  U   Zope/trunk/src/DocumentTemplate/DT_Raise.py
  A   Zope/trunk/src/DocumentTemplate/tests/test_DT_Raise.py

-=-
Modified: Zope/trunk/src/DocumentTemplate/DT_Raise.py
===================================================================
--- Zope/trunk/src/DocumentTemplate/DT_Raise.py	2009-05-06 15:48:10 UTC (rev 99791)
+++ Zope/trunk/src/DocumentTemplate/DT_Raise.py	2009-05-06 16:19:56 UTC (rev 99792)
@@ -27,6 +27,7 @@
 __version__='$Revision: 1.13 $'[11:-2]
 
 from zExceptions import upgradeException
+from zExceptions import convertExceptionType
 from DocumentTemplate.DT_Util import name_param
 from DocumentTemplate.DT_Util import parse_params
 from DocumentTemplate.DT_Util import render_blocks
@@ -49,12 +50,16 @@
     def render(self,md):
         expr = self.expr
         if expr is None:
-            t = __builtins__.get(self.__name__, RuntimeError)
+            t = convertExceptionType(self.__name__)
+            if t is None:
+                t = RuntimeError
         else:
             try:
                 t = expr.eval(md)
             except:
-                t = InvalidErrorTypeExpression
+                t = convertExceptionType(self.__name__)
+                if t is None:
+                    t = InvalidErrorTypeExpression
 
         try:
             v = render_blocks(self.section, md)

Added: Zope/trunk/src/DocumentTemplate/tests/test_DT_Raise.py
===================================================================
--- Zope/trunk/src/DocumentTemplate/tests/test_DT_Raise.py	                        (rev 0)
+++ Zope/trunk/src/DocumentTemplate/tests/test_DT_Raise.py	2009-05-06 16:19:56 UTC (rev 99792)
@@ -0,0 +1,69 @@
+import unittest
+
+class Test_Raise(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from DocumentTemplate.DT_Raise import Raise
+        return Raise
+
+    def _makeOne(self, type=None, expr=None):
+        args = []
+        if type is not None:
+            args.append('type="%s"' % type)
+        if expr is not None:
+            args.append('expr="%s"' % expr)
+        blocks = [('raise', ' '.join(args), DummySection())]
+        return self._getTargetClass()(blocks)
+
+    def test_ctor_w_type(self):
+        raiser = self._makeOne(type='Redirect')
+        self.assertEqual(raiser.__name__, 'Redirect')
+        self.assertEqual(raiser.expr, None)
+
+    def test_ctor_w_expr(self):
+        from DocumentTemplate.DT_Util import Eval
+        raiser = self._makeOne(expr='SyntaxError')
+        self.assertEqual(raiser.__name__, 'SyntaxError')
+        self.assertEqual(raiser.expr.expr, 'SyntaxError')
+
+    def test_render_w_type_builtin_exception(self):
+        from DocumentTemplate.DT_Util import TemplateDict
+        raiser = self._makeOne(type='SyntaxError')
+        self.assertRaises(SyntaxError, raiser.render, TemplateDict())
+
+    def test_render_w_type_zExceptions_exception(self):
+        from DocumentTemplate.DT_Util import TemplateDict
+        from zExceptions import Redirect
+        raiser = self._makeOne(type='Redirect')
+        self.assertRaises(Redirect, raiser.render, TemplateDict())
+
+    def test_render_w_type_nonesuch(self):
+        from DocumentTemplate.DT_Util import TemplateDict
+        raiser = self._makeOne(type='NonesuchError')
+        self.assertRaises(RuntimeError, raiser.render, TemplateDict())
+
+    def test_render_w_expr_builtin_exception(self):
+        from DocumentTemplate.DT_Util import TemplateDict
+        raiser = self._makeOne(expr='SyntaxError')
+        self.assertRaises(SyntaxError, raiser.render, TemplateDict())
+
+    def test_render_w_expr_zExceptions_exception(self):
+        from DocumentTemplate.DT_Util import TemplateDict
+        from zExceptions import Redirect
+        raiser = self._makeOne(expr='Redirect')
+        self.assertRaises(Redirect, raiser.render, TemplateDict())
+
+    def test_render_w_expr_nonesuch(self):
+        from DocumentTemplate.DT_Raise import InvalidErrorTypeExpression
+        from DocumentTemplate.DT_Util import TemplateDict
+        raiser = self._makeOne(expr='NonesuchError')
+        self.assertRaises(InvalidErrorTypeExpression,
+                          raiser.render, TemplateDict())
+
+class DummySection:
+    blocks = ['dummy']
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(Test_Raise),
+    ))



More information about the Zope-Checkins mailing list