Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
b217d733
Commit
b217d733
authored
May 06, 2009
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LP #372629: fix <dtml-raise> for zExceptions.
parent
92754b71
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
2 deletions
+76
-2
src/DocumentTemplate/DT_Raise.py
src/DocumentTemplate/DT_Raise.py
+7
-2
src/DocumentTemplate/tests/test_DT_Raise.py
src/DocumentTemplate/tests/test_DT_Raise.py
+69
-0
No files found.
src/DocumentTemplate/DT_Raise.py
View file @
b217d733
...
...
@@ -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
)
...
...
src/DocumentTemplate/tests/test_DT_Raise.py
0 → 100644
View file @
b217d733
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
),
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment