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
2c0c8869
Commit
2c0c8869
authored
May 08, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove sclerotic junk from DocumentTemplate tests.
parent
6de33787
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
115 additions
and
111 deletions
+115
-111
src/DocumentTemplate/tests/testDTML.py
src/DocumentTemplate/tests/testDTML.py
+65
-74
src/DocumentTemplate/tests/testDTMLUnicode.py
src/DocumentTemplate/tests/testDTMLUnicode.py
+4
-15
src/DocumentTemplate/tests/test_DT_Raise.py
src/DocumentTemplate/tests/test_DT_Raise.py
+0
-1
src/DocumentTemplate/tests/test_DT_Var.py
src/DocumentTemplate/tests/test_DT_Var.py
+2
-1
src/DocumentTemplate/tests/testustr.py
src/DocumentTemplate/tests/testustr.py
+44
-20
No files found.
src/DocumentTemplate/tests/testDTML.py
View file @
2c0c8869
...
...
@@ -13,59 +13,19 @@
"""Document Template Tests
"""
__rcs_id__
=
'$Id$'
__version__
=
'$Revision: 1.15 $'
[
11
:
-
2
]
import
sys
,
os
,
cgi
import
unittest
if
__name__
==
'__main__'
:
here
=
os
.
curdir
else
:
from
DocumentTemplate
import
tests
here
=
tests
.
__path__
[
0
]
def
read_file
(
name
):
f
=
open
(
os
.
path
.
join
(
here
,
name
),
'r'
)
res
=
f
.
read
()
f
.
close
()
return
res
from
DocumentTemplate.DT_HTML
import
HTML
,
String
from
ExtensionClass
import
Base
class
D
:
__allow_access_to_unprotected_subobjects__
=
1
def
__init__
(
self
,
**
kw
):
for
k
,
v
in
kw
.
items
():
self
.
__dict__
[
k
]
=
v
def
__repr__
(
self
):
return
"D(%s)"
%
`self.__dict__`
class
DTMLTests
(
unittest
.
TestCase
):
def
d
(
**
kw
):
return
kw
docutils_include_warning
=
'''
\
<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils"><string></tt>, line 1)</p>
<p>"include" directive disabled.</p>'''
docutils_raw_warning
=
'''
\
<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils"><string></tt>, line 1)</p>
<p>"raw" directive disabled.</p>'''
class
PukeError
(
Exception
):
"""Exception raised in test code."""
class
DTMLTests
(
unittest
.
TestCase
):
doc_class
=
HTML
def
_get_doc_class
(
self
):
from
DocumentTemplate.DT_HTML
import
HTML
return
HTML
doc_class
=
property
(
_get_doc_class
,)
def
testBatchingEtc
(
self
):
def
item
(
key
,
**
kw
):
return
(
key
,
kw
)
def
item2
(
key
,
**
kw
):
return
kw
class
item_class
:
def
__init__
(
self
,
key
,
**
kw
):
for
k
in
kw
.
keys
():
self
.
__dict__
[
k
]
=
kw
[
k
]
def
item
(
key
,
**
kw
):
return
(
key
,
kw
)
items
=
(
item
(
1
,
dealer
=
'Bay Chevy'
,
make
=
'Chevrolet'
,
...
...
@@ -176,12 +136,11 @@ class DTMLTests (unittest.TestCase):
self
.
assertEqual
(
res
,
expected
)
def
testSequenceSummaries
(
self
):
def
d
(
**
kw
):
return
kw
data
=
(
d
(
name
=
'jim'
,
age
=
38
),
# d(name='kak', age=40),
d
(
name
=
'will'
,
age
=
7
),
d
(
name
=
'drew'
,
age
=
4
),
d
(
name
=
'ches'
,
age
=
1
),
data
=
(
dict
(
name
=
'jim'
,
age
=
38
),
# dict(name='kak', age=40),
dict
(
name
=
'will'
,
age
=
7
),
dict
(
name
=
'drew'
,
age
=
4
),
dict
(
name
=
'ches'
,
age
=
1
),
)
html
=
self
.
doc_class
(
'<dtml-in data mapping>'
'<dtml-if sequence-end>'
...
...
@@ -222,6 +181,7 @@ class DTMLTests (unittest.TestCase):
assert
res
==
expected
,
res
def
testSimpleString
(
self
):
from
DocumentTemplate.DT_HTML
import
String
dt
=
String
(
'%(name)s'
)
res
=
dt
(
name
=
'Chris'
)
expected
=
'Chris'
...
...
@@ -229,6 +189,7 @@ class DTMLTests (unittest.TestCase):
def
testStringDateFormatting
(
self
):
import
DateTime
from
DocumentTemplate.DT_HTML
import
String
html
=
String
(
"%(name capitalize spacify)s is "
"%(date fmt=year)s/%(date fmt=month)s/%(date fmt=day)s"
)
res
=
html
(
date
=
DateTime
.
DateTime
(
"2001-04-27"
),
...
...
@@ -357,6 +318,7 @@ foo bar
self
.
assert_
(
docutils_include_warning
in
result
)
def
test_fmt_reST_raw_directive_disabled
(
self
):
from
cgi
import
escape
EXPECTED
=
'<h1>HELLO WORLD</h1>'
source
=
'.. raw:: html
\
n
\
n
%s
\
n
'
%
EXPECTED
html
=
self
.
doc_class
(
'<dtml-var name="foo" fmt="restructured-text">'
)
...
...
@@ -367,7 +329,7 @@ foo bar
# verbatimly in the rendered output. Instead a warning
# message is presented:
self
.
assert_
(
EXPECTED
not
in
result
)
self
.
assert_
(
cgi
.
escape
(
EXPECTED
)
in
result
)
self
.
assert_
(
escape
(
EXPECTED
)
in
result
)
self
.
assert_
(
docutils_raw_warning
in
result
)
def
test_fmt_reST_raw_directive_file_option_raises
(
self
):
...
...
@@ -395,6 +357,7 @@ foo bar
self
.
assert_
(
docutils_raw_warning
in
result
)
def
testPropogatedError
(
self
):
from
ExtensionClass
import
Base
class
foo
:
def
__len__
(
self
):
return
9
...
...
@@ -434,7 +397,8 @@ foo bar
assert
0
,
'Puke error not propogated'
def
testRenderCallable
(
self
):
"Test automatic rendering of callable objects"
#Test automatic rendering of callable objects
from
ExtensionClass
import
Base
class
C
(
Base
):
__allow_access_to_unprotected_subobjects__
=
1
x
=
1
...
...
@@ -483,7 +447,9 @@ foo bar
def
testNoItemPush
(
self
):
data
=
d
(
sec
=
'B'
,
name
=
'XXX'
,
sub
=
(
d
(
name
=
'b1'
),
d
(
name
=
'b2'
,
sec
=
'XXX'
)))
data
=
dict
(
sec
=
'B'
,
name
=
'XXX'
,
sub
=
(
dict
(
name
=
'b1'
),
dict
(
name
=
'b2'
,
sec
=
'XXX'
)))
html
=
"""
<dtml-with data mapping><dtml-in sub no_push_item>
<dtml-var sec>.<dtml-with sequence-item mapping><dtml-var name></dtml-with>
...
...
@@ -496,11 +462,11 @@ foo bar
def
testBasicHTMLIn
(
self
):
data
=
(
d
(
name
=
'jim'
,
age
=
39
),
d
(
name
=
'kak'
,
age
=
29
),
d
(
name
=
'will'
,
age
=
8
),
d
(
name
=
'andrew'
,
age
=
5
),
d
(
name
=
'chessie'
,
age
=
2
),
d
ict
(
name
=
'jim'
,
age
=
39
),
d
ict
(
name
=
'kak'
,
age
=
29
),
d
ict
(
name
=
'will'
,
age
=
8
),
d
ict
(
name
=
'andrew'
,
age
=
5
),
d
ict
(
name
=
'chessie'
,
age
=
2
),
)
html
=
"""
...
...
@@ -519,7 +485,7 @@ foo bar
assert
result
==
expected
,
result
def
testBasicHTMLIn2
(
self
):
xxx
=
(
D
(
name
=
1
),
D
(
name
=
2
),
D
(
name
=
3
))
xxx
=
(
D
ummy
(
name
=
1
),
Dummy
(
name
=
2
),
Dummy
(
name
=
3
))
html
=
"""
<!--#in xxx-->
<!--#var name -->
...
...
@@ -543,7 +509,7 @@ foo bar
assert
result
==
expected
,
result
def
testHTMLInElse
(
self
):
xxx
=
(
D
(
name
=
1
),
D
(
name
=
2
),
D
(
name
=
3
))
xxx
=
(
D
ummy
(
name
=
1
),
Dummy
(
name
=
2
),
Dummy
(
name
=
3
))
html
=
"""
<!--#in data mapping-->
<!--#var name-->, <!--#var age-->
...
...
@@ -562,12 +528,13 @@ foo bar
assert
result
==
expected
,
result
def
testBasicStringIn
(
self
):
from
DocumentTemplate.DT_HTML
import
String
data
=
(
d
(
name
=
'jim'
,
age
=
39
),
d
(
name
=
'kak'
,
age
=
29
),
d
(
name
=
'will'
,
age
=
8
),
d
(
name
=
'andrew'
,
age
=
5
),
d
(
name
=
'chessie'
,
age
=
2
),
d
ict
(
name
=
'jim'
,
age
=
39
),
d
ict
(
name
=
'kak'
,
age
=
29
),
d
ict
(
name
=
'will'
,
age
=
8
),
d
ict
(
name
=
'andrew'
,
age
=
5
),
d
ict
(
name
=
'chessie'
,
age
=
2
),
)
s
=
"""
%(in data mapping)[
...
...
@@ -584,13 +551,37 @@ foo bar
result
=
String
(
s
)(
data
=
data
)
assert
expected
==
result
,
result
def
read_file
(
name
):
import
os
from
DocumentTemplate
import
tests
here
=
tests
.
__path__
[
0
]
f
=
open
(
os
.
path
.
join
(
here
,
name
),
'r'
)
res
=
f
.
read
()
f
.
close
()
return
res
class
Dummy
:
__allow_access_to_unprotected_subobjects__
=
1
def
__init__
(
self
,
**
kw
):
self
.
__dict__
.
update
(
kw
)
def
__repr__
(
self
):
return
"Dummy(%s)"
%
`self.__dict__`
docutils_include_warning
=
'''
\
<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils"><string></tt>, line 1)</p>
<p>"include" directive disabled.</p>'''
docutils_raw_warning
=
'''
\
<p class="system-message-title">System Message: WARNING/2 (<tt class="docutils"><string></tt>, line 1)</p>
<p>"raw" directive disabled.</p>'''
class
PukeError
(
Exception
):
"""Exception raised in test code."""
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
DTMLTests
)
)
return
suite
def
main
():
unittest
.
TextTestRunner
().
run
(
test_suite
())
if
__name__
==
'__main__'
:
main
()
src/DocumentTemplate/tests/testDTMLUnicode.py
View file @
2c0c8869
...
...
@@ -12,16 +12,8 @@
##############################################################################
"""Document Template Tests
"""
__rcs_id__
=
'$Id$'
__version__
=
'$Revision: 1.4 $'
[
11
:
-
2
]
import
sys
,
os
import
unittest
from
DocumentTemplate.DT_HTML
import
HTML
,
String
from
ExtensionClass
import
Base
class
force_str
:
# A class whose string representation is not always a plain string:
def
__init__
(
self
,
s
):
...
...
@@ -31,7 +23,10 @@ class force_str:
class
DTMLUnicodeTests
(
unittest
.
TestCase
):
doc_class
=
HTML
def
_get_doc_class
(
self
):
from
DocumentTemplate.DT_HTML
import
HTML
return
HTML
doc_class
=
property
(
_get_doc_class
,)
def
testAA
(
self
):
html
=
self
.
doc_class
(
'<dtml-var a><dtml-var b>'
)
...
...
@@ -91,9 +86,3 @@ def test_suite():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
DTMLUnicodeTests
)
)
return
suite
def
main
():
unittest
.
TextTestRunner
().
run
(
test_suite
())
if
__name__
==
'__main__'
:
main
()
src/DocumentTemplate/tests/test_DT_Raise.py
View file @
2c0c8869
...
...
@@ -21,7 +21,6 @@ class Test_Raise(unittest.TestCase):
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'
)
...
...
src/DocumentTemplate/tests/test_DT_Var.py
View file @
2c0c8869
...
...
@@ -16,7 +16,6 @@ $Id$
"""
import
unittest
,
doctest
from
DocumentTemplate
import
DT_Var
class
TestNewlineToBr
(
doctest
.
DocTestCase
):
...
...
@@ -25,6 +24,7 @@ class TestNewlineToBr(doctest.DocTestCase):
newline_to_br should work identically with either DOS-style or
Unix-style newlines.
>>> from DocumentTemplate import DT_Var
>>> text = '''
... line one
... line two
...
...
@@ -47,6 +47,7 @@ class TestNewlineToBr(doctest.DocTestCase):
def
test_newline_to_br_tainted
(
self
):
"""
>>> from DocumentTemplate import DT_Var
>>> text = '''
... <li>line one</li>
... <li>line two</li>
...
...
src/DocumentTemplate/tests/testustr.py
View file @
2c0c8869
...
...
@@ -17,7 +17,6 @@ $Id$
import
unittest
from
DocumentTemplate.ustr
import
ustr
class
force_str
:
...
...
@@ -40,45 +39,70 @@ class Bar(unicode):
class
UnicodeTests
(
unittest
.
TestCase
):
def
testPlain
(
self
):
def
test_bare_string_literall
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
'hello'
)
assert
a
==
'hello'
,
`a`
self
.
assertEqual
(
a
,
'hello'
)
def
test_with_force_str
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
force_str
(
'hello'
))
assert
a
==
'hello'
,
`a`
self
.
assertEqual
(
a
,
'hello'
)
def
test_with_non_ascii_char
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
chr
(
200
))
assert
a
==
chr
(
200
),
`a`
self
.
assertEqual
(
a
,
chr
(
200
))
def
test_with_force_str_non_ascii_char
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
force_str
(
chr
(
200
)))
assert
a
==
chr
(
200
),
`a`
self
.
assertEqual
(
a
,
chr
(
200
))
def
test_with_int
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
22
)
assert
a
==
'22'
,
`a`
self
.
assertEqual
(
a
,
'22'
)
def
test_with_list
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
([
1
,
2
,
3
])
assert
a
==
'[1, 2, 3]'
,
`a`
self
.
assertEqual
(
a
,
'[1, 2, 3]'
)
def
testUnicode
(
self
):
def
test_w_unicode_literal
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
u'hello'
)
assert
a
==
'hello'
,
`a`
self
.
assertEqual
(
a
,
'hello'
)
def
test_w_force_str_unicode_literal
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
force_str
(
u'hello'
))
assert
a
==
'hello'
,
`a`
self
.
assertEqual
(
a
,
'hello'
)
def
test_w_unichr
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
unichr
(
200
))
assert
a
==
unichr
(
200
),
`a`
self
.
assertEqual
(
a
,
unichr
(
200
))
def
test_w_force_str_unichr
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
force_str
(
unichr
(
200
)))
assert
a
==
unichr
(
200
),
`a`
self
.
assertEqual
(
a
,
unichr
(
200
))
def
testExceptions
(
self
):
def
test_w_unichr_in_exception
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
ValueError
(
unichr
(
200
)))
assert
a
==
unichr
(
200
),
`a`
self
.
assertEqual
(
a
,
unichr
(
200
))
def
testCustomStrings
(
self
):
from
DocumentTemplate.ustr
import
ustr
a
=
ustr
(
Foo
(
'foo'
))
self
.
failUnless
Equal
(
type
(
a
),
Foo
)
self
.
assert
Equal
(
type
(
a
),
Foo
)
a
=
ustr
(
Bar
(
'bar'
))
self
.
failUnless
Equal
(
type
(
a
),
Bar
)
self
.
assert
Equal
(
type
(
a
),
Bar
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
suite
.
addTest
(
unittest
.
makeSuite
(
UnicodeTests
)
)
return
suite
if
__name__
==
'__main__'
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
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