Commit b217d733 authored by Tres Seaver's avatar Tres Seaver

LP #372629: fix <dtml-raise> for zExceptions.

parent 92754b71
......@@ -27,6 +27,7 @@ __rcs_id__='$Id$'
__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 @@ class Raise:
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)
......
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),
))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment