[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate/tests - __init__.py:1.1.2.1 batch.py:1.1.2.1 framework.py:1.1.2.1 run.py:1.1.2.1 testDTMLTests.py:1.1.2.1 testExpressions.py:1.1.2.1 testHTMLTests.py:1.1.2.1 testTALES.py:1.1.2.1 util.py:1.1.2.1
Fred Drake Jr
fdrake@acm.org
Mon, 19 Nov 2001 18:55:08 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/PageTemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv2007
Added Files:
Tag: Zope-3x-branch
__init__.py batch.py framework.py run.py testDTMLTests.py
testExpressions.py testHTMLTests.py testTALES.py util.py
Log Message:
Integrate original page template tests.
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/__init__.py ===
def all():
import testTALES
return testTALES.test_suite()
class harness1:
def __init__(self):
self.__callstack = []
def _assert_(self, name, *args, **kwargs):
self.__callstack.append((name, args, kwargs))
def _complete_(self):
assert len(self.__callstack) == 0, "Harness methods called"
def __getattr__(self, name):
cs = self.__callstack
assert len(cs), 'Unexpected harness method call "%s".' % name
assert cs[0][0] == name, (
'Harness method name "%s" called, "%s" expected.' %
(name, cs[0][0]) )
return self._method_
def _method_(self, *args, **kwargs):
name, aargs, akwargs = self.__callstack.pop(0)
assert aargs == args, "Harness method arguments"
assert akwargs == kwargs, "Harness method keyword args"
class harness2(harness1):
def _assert_(self, name, result, *args, **kwargs):
self.__callstack.append((name, result, args, kwargs))
def _method_(self, *args, **kwargs):
name, result, aargs, akwargs = self.__callstack.pop(0)
assert aargs == args, "Harness method arguments"
assert akwargs == kwargs, "Harness method keyword args"
return result
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/batch.py ===
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
######################################################################
# Sequence batching support
__allow_access_to_unprotected_subobjects__={'batch': 1}
__roles__=None
class batch:
"""Create a sequence batch"""
def __init__(self, sequence, size, start=0, end=0,
orphan=3, overlap=0):
start=start+1
start,end,sz=opt(start,end,size,orphan,sequence)
self._last=end-1
self._first=start-1
self._sequence=sequence
self._size=size
self._start=start
self._end=end
self._orphan=orphan
self._overlap=overlap
def previous_sequence(self): return self._first
def previous_sequence_end_number(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return end
def previous_sequence_start_number(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return start
def previous_sequence_end_item(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return self._sequence[end-1]
def previous_sequence_start_item(self):
start,end,spam=opt(0, self._start-1+self._overlap,
self._size, self._orphan, self._sequence)
return self._sequence[start-1]
def next_sequence_end_number(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return end
def next_sequence_start_number(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return start
def next_sequence_end_item(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return self._sequence[end-1]
def next_sequence_start_item(self):
start,end,spam=opt(self._end+1-self._overlap, 0,
self._size, self._orphan, self._sequence)
return self._sequence[start-1]
def next_sequence(self):
try: self._sequence[self._end]
except IndexError: return 0
else: return 1
def __getitem__(self, index):
if index > self._last: raise IndexError, index
return self._sequence[index+self._first]
def opt(start,end,size,orphan,sequence):
if size < 1:
if start > 0 and end > 0 and end >= start:
size=end+1-start
else: size=7
if start > 0:
try: sequence[start-1]
except: start=len(sequence)
if end > 0:
if end < start: end=start
else:
end=start+size-1
try: sequence[end+orphan-1]
except: end=len(sequence)
elif end > 0:
try: sequence[end-1]
except: end=len(sequence)
start=end+1-size
if start - 1 < orphan: start=1
else:
start=1
end=start+size-1
try: sequence[end+orphan-1]
except: end=len(sequence)
return start,end,size
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/framework.py ===
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
######################################################################
# Set up unit testing framework
#
# The following code should be at the top of every test module:
#
# import os, sys
# execfile(os.path.join(sys.path[0], 'framework.py'))
#
# ...and the following at the bottom:
#
# if __name__ == '__main__':
# main()
import string
scriptdir = sys.path[0]
input_dir = os.path.join(scriptdir, 'input')
output_dir = os.path.join(scriptdir, 'output')
if not sys.modules.has_key('unittest'):
if os.path.abspath(scriptdir) == os.path.abspath('.'):
# We're in the tests directory, and need to find unittest.
cwd = os.getcwd()
while 1:
for ext in 'py', 'pyc', 'pyo', 'pyd':
if os.path.isfile(os.path.join(cwd, 'unittest.' + ext)):
break
else:
cwd, lastdir = os.path.split(cwd)
if lastdir:
continue
break
sys.path.insert(1, cwd)
else:
# We must be in the same directory as unittest
sys.path.insert(1, '')
import unittest
TestRunner = unittest.TextTestRunner
def read_input(filename):
filename = os.path.join(input_dir, filename)
return open(filename, 'r').read()
def read_output(filename):
filename = os.path.join(output_dir, filename)
return open(filename, 'r').read()
def main():
if len(sys.argv) > 1:
errs = globals()[sys.argv[1]]()
else:
errs = TestRunner().run(test_suite())
sys.exit(errs and 1 or 0)
def debug():
test_suite().debug()
def pdebug():
import pdb
pdb.run('debug()')
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/run.py ===
#! /usr/bin/env python
"""Run all tests."""
import os, sys
execfile(os.path.join(sys.path[0], 'framework.py'))
def test_suite():
suite = unittest.TestSuite()
for mname in ('DTMLTests', 'HTMLTests', 'Expressions', 'TALES'):
m = __import__('test' + mname)
suite.addTest(m.test_suite())
return suite
if __name__ == "__main__":
main()
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/testDTMLTests.py ===
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
import os, sys, unittest
from Zope.PageTemplate.tests import util
from Zope.PageTemplate.PageTemplate import PageTemplate
class DTMLTests(unittest.TestCase):
def setUp(self):
self.t=(PageTemplate())
def check1(self):
"""DTML test 1: if, in, and var:
%(comment)[ blah %(comment)]
<html><head><title>Test of documentation templates</title></head>
<body>
%(if args)[
<dl><dt>The arguments to this test program were:<p>
<dd>
<ul>
%(in args)[
<li>Argument number %(num)d was %(arg)s
%(in args)]
</ul></dl><p>
%(if args)]
%(else args)[
No arguments were given.<p>
%(else args)]
And thats da trooth.
</body></html>
"""
tal = util.read_input('DTML1.html')
self.t.write(tal)
aa=util.argv(('one', 'two', 'three', 'cha', 'cha', 'cha'))
o=self.t.__of__(aa)()
expect = util.read_output('DTML1a.html')
util.check_xml(expect, o)
aa=util.argv(())
o=self.t.__of__(aa)()
expect = util.read_output('DTML1b.html')
util.check_xml(expect, o)
def check3(self):
"""DTML test 3: batches and formatting:
<html><head><title>Test of documentation templates</title></head>
<body>
<!--#if args-->
The arguments were:
<!--#in args size=size end=end-->
<!--#if previous-sequence-->
(<!--#var previous-sequence-start-arg-->-
<!--#var previous-sequence-end-arg-->)
<!--#/if previous-sequence-->
<!--#if sequence-start-->
<dl>
<!--#/if sequence-start-->
<dt><!--#var sequence-arg-->.</dt>
<dd>Argument <!--#var num fmt=d--> was <!--#var arg--></dd>
<!--#if next-sequence-->
(<!--#var next-sequence-start-arg-->-
<!--#var next-sequence-end-arg-->)
<!--#/if next-sequence-->
<!--#/in args-->
</dl>
<!--#else args-->
No arguments were given.<p>
<!--#/if args-->
And I\'m 100% sure!
</body></html>
"""
tal = util.read_input('DTML3.html')
self.t.write(tal)
aa=util.argv(('one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten',
'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen',
'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty',
))
from Zope.PageTemplate.tests import batch
o=self.t.__of__(aa)(batch=batch.batch(aa.args, 5))
expect = util.read_output('DTML3.html')
util.check_xml(expect, o)
def test_suite():
return unittest.makeSuite(DTMLTests, 'check')
if __name__=='__main__':
main()
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/testExpressions.py ===
import os, sys, unittest
from Zope.PageTemplate import Expressions
class ExpressionTests(unittest.TestCase):
def testCompile(self):
'''Test expression compilation'''
e = Expressions.getEngine()
for p in ('x', 'x/y', 'x/y/z'):
e.compile(p)
e.compile('path:a|b|c/d/e')
e.compile('string:Fred')
e.compile('string:A$B')
e.compile('string:a ${x/y} b ${y/z} c')
e.compile('python: 2 + 2')
e.compile('python: 2 \n+\n 2\n')
def test_suite():
return unittest.makeSuite(ExpressionTests)
if __name__=='__main__':
main()
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/testHTMLTests.py ===
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
import os, sys, unittest
from Zope.PageTemplate.tests import util
from Zope.PageTemplate.PageTemplate import PageTemplate
class Folder:
pass
class HTMLTests(unittest.TestCase):
def setUp(self):
self.folder = f = Folder()
f.laf = PageTemplate()
f.t = PageTemplate()
def getProducts(self):
return [
{'description': 'This is the tee for those who LOVE Zope. '
'Show your heart on your tee.',
'price': 12.99, 'image': 'smlatee.jpg'
},
{'description': 'This is the tee for Jim Fulton. '
'He\'s the Zope Pope!',
'price': 11.99, 'image': 'smpztee.jpg'
},
]
def check1(self):
laf = self.folder.laf
laf.write(util.read_input('TeeShopLAF.html'))
expect = util.read_output('TeeShopLAF.html')
util.check_html(expect, laf())
def check2(self):
self.folder.laf.write(util.read_input('TeeShopLAF.html'))
t = self.folder.t
t.write(util.read_input('TeeShop2.html'))
expect = util.read_output('TeeShop2.html')
out = t(getProducts=self.getProducts)
util.check_html(expect, out)
def check3(self):
self.folder.laf.write(util.read_input('TeeShopLAF.html'))
t = self.folder.t
t.write(util.read_input('TeeShop1.html'))
expect = util.read_output('TeeShop1.html')
out = t(getProducts=self.getProducts)
util.check_html(expect, out)
def checkSimpleLoop(self):
t = self.folder.t
t.write(util.read_input('Loop1.html'))
expect = util.read_output('Loop1.html')
out = t()
util.check_html(expect, out)
def checkGlobalsShadowLocals(self):
t = self.folder.t
t.write(util.read_input('GlobalsShadowLocals.html'))
expect = util.read_output('GlobalsShadowLocals.html')
out = t()
util.check_html(expect, out)
def checkStringExpressions(self):
t = self.folder.t
t.write(util.read_input('StringExpression.html'))
expect = util.read_output('StringExpression.html')
out = t()
util.check_html(expect, out)
def checkReplaceWithNothing(self):
t = self.folder.t
t.write(util.read_input('CheckNothing.html'))
expect = util.read_output('CheckNothing.html')
out = t()
util.check_html(expect, out)
def checkWithXMLHeader(self):
t = self.folder.t
t.write(util.read_input('CheckWithXMLHeader.html'))
expect = util.read_output('CheckWithXMLHeader.html')
out = t()
util.check_html(expect, out)
def checkNotExpression(self):
t = self.folder.t
t.write(util.read_input('CheckNotExpression.html'))
expect = util.read_output('CheckNotExpression.html')
out = t()
util.check_html(expect, out)
def checkPathNothing(self):
t = self.folder.t
t.write(util.read_input('CheckPathNothing.html'))
expect = util.read_output('CheckPathNothing.html')
out = t()
util.check_html(expect, out)
def checkPathAlt(self):
t = self.folder.t
t.write(util.read_input('CheckPathAlt.html'))
expect = util.read_output('CheckPathAlt.html')
out = t()
util.check_html(expect, out)
def test_suite():
return unittest.makeSuite(HTMLTests, 'check')
if __name__=='__main__':
main()
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/testTALES.py ===
import os, sys, unittest
from Zope.PageTemplate import TALES
from Zope.PageTemplate.tests import harness1
class TALESTests(unittest.TestCase):
def testIterator0(self):
'''Test sample Iterator class'''
context = harness1()
it = TALES.Iterator('name', (), context)
assert not it.next(), "Empty iterator"
context._complete_()
def testIterator1(self):
'''Test sample Iterator class'''
context = harness1()
it = TALES.Iterator('name', (1,), context)
context._assert_('setLocal', 'name', 1)
assert it.next() and not it.next(), "Single-element iterator"
context._complete_()
def testIterator2(self):
'''Test sample Iterator class'''
context = harness1()
it = TALES.Iterator('text', 'text', context)
for c in 'text':
context._assert_('setLocal', 'text', c)
for c in 'text':
assert it.next(), "Multi-element iterator"
assert not it.next(), "Multi-element iterator"
context._complete_()
def testRegisterType(self):
'''Test expression type registration'''
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
assert e.getTypes()['simple'] == TALES.SimpleExpr
def testRegisterTypeUnique(self):
'''Test expression type registration uniqueness'''
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
try:
e.registerType('simple', TALES.SimpleExpr)
except TALES.RegistrationError:
pass
else:
assert 0, "Duplicate registration accepted."
def testRegisterTypeNameConstraints(self):
'''Test constraints on expression type names'''
e = TALES.Engine()
for name in '1A', 'A!', 'AB ':
try:
e.registerType(name, TALES.SimpleExpr)
except TALES.RegistrationError:
pass
else:
assert 0, 'Invalid type name "%s" accepted.' % name
def testCompile(self):
'''Test expression compilation'''
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
ce = e.compile('simple:x')
assert ce(None) == ('simple', 'x'), (
'Improperly compiled expression %s.' % `ce`)
def testGetContext(self):
'''Test Context creation'''
TALES.Engine().getContext()
TALES.Engine().getContext(v=1)
TALES.Engine().getContext(x=1, y=2)
def getContext(self, **kws):
e = TALES.Engine()
e.registerType('simple', TALES.SimpleExpr)
return apply(e.getContext, (), kws)
def testContext0(self):
'''Test use of Context'''
se = self.getContext().evaluate('simple:x')
assert se == ('simple', 'x'), (
'Improperly evaluated expression %s.' % `se`)
def testVariables(self):
'''Test variables'''
ctxt = self.getContext()
c = ctxt.vars
ctxt.beginScope()
ctxt.setLocal('v1', 1)
ctxt.setLocal('v2', 2)
assert c['v1'] == 1, 'Variable "v1"'
ctxt.beginScope()
ctxt.setLocal('v1', 3)
ctxt.setGlobal('g', 1)
assert c['v1'] == 3, 'Inner scope'
assert c['v2'] == 2, 'Outer scope'
assert c['g'] == 1, 'Global'
ctxt.endScope()
assert c['v1'] == 1, "Uncovered local"
assert c['g'] == 1, "Global from inner scope"
ctxt.endScope()
def test_suite():
return unittest.makeSuite(TALESTests)
if __name__=='__main__':
main()
=== Added File Zope3/lib/python/Zope/PageTemplate/tests/util.py ===
##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
#
# Copyright (c) Digital Creations. All rights reserved.
#
# This license has been certified as Open Source(tm).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions in source code must retain the above copyright
# notice, this list of conditions, and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions, and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. Digital Creations requests that attribution be given to Zope
# in any manner possible. Zope includes a "Powered by Zope"
# button that is installed by default. While it is not a license
# violation to remove this button, it is requested that the
# attribution remain. A significant investment has been put
# into Zope, and this effort will continue if the Zope community
# continues to grow. This is one way to assure that growth.
#
# 4. All advertising materials and documentation mentioning
# features derived from or use of this software must display
# the following acknowledgement:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# In the event that the product being advertised includes an
# intact Zope distribution (with copyright and license included)
# then this clause is waived.
#
# 5. Names associated with Zope or Digital Creations must not be used to
# endorse or promote products derived from this software without
# prior written permission from Digital Creations.
#
# 6. Modified redistributions of any form whatsoever must retain
# the following acknowledgment:
#
# "This product includes software developed by Digital Creations
# for use in the Z Object Publishing Environment
# (http://www.zope.org/)."
#
# Intact (re-)distributions of any official Zope release do not
# require an external acknowledgement.
#
# 7. Modifications are encouraged but must be packaged separately as
# patches to official Zope releases. Distributions that do not
# clearly separate the patches from the original work must be clearly
# labeled as unofficial distributions. Modifications which do not
# carry the name Zope may be packaged in any form, as long as they
# conform to all of the clauses above.
#
#
# Disclaimer
#
# THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This software consists of contributions made by Digital Creations and
# many individuals on behalf of Digital Creations. Specific
# attributions are listed in the accompanying credits file.
#
##############################################################################
######################################################################
# Utility facilities to aid setting things up.
import os, sys, string, re
class Bruce:
__allow_access_to_unprotected_subobjects__=1
def __str__(self): return 'bruce'
def __int__(self): return 42
def __float__(self): return 42.0
def keys(self): return ['bruce']*7
def values(self): return [self]*7
def items(self): return [('bruce',self)]*7
def __len__(self): return 7
def __getitem__(self,index):
if (type(index) is type(1) and
(index < 0 or index > 6)): raise IndexError, index
return self
isDocTemp=0
def __getattr__(self,name):
if name[:1]=='_': raise AttributeError, name
return self
bruce=Bruce()
class arg:
__allow_access_to_unprotected_subobjects__=1
def __init__(self,nn,aa): self.num, self.arg = nn, aa
def __str__(self): return str(self.arg)
class argv:
__allow_access_to_unprotected_subobjects__=1
def __init__(self, argv=sys.argv[1:]):
args=self.args=[]
for aa in argv:
args.append(arg(len(args)+1,aa))
def items(self):
return map(lambda a: ('spam%d' % a.num, a), self.args)
def values(self): return self.args
def getPhysicalRoot(self):
return self
def nicerange(lo, hi):
if hi <= lo+1:
return str(lo+1)
else:
return "%d,%d" % (lo+1, hi)
def check_html(s1, s2):
s1 = normalize_html(s1)
s2 = normalize_html(s2)
if s1!=s2:
print
from OFS.ndiff import SequenceMatcher, dump, IS_LINE_JUNK
a = string.split(s1, '\n')
b = string.split(s2, '\n')
def add_nl(s):
return s + '\n'
a = map(add_nl, a)
b = map(add_nl, b)
cruncher=SequenceMatcher(isjunk=IS_LINE_JUNK, a=a, b=b)
for tag, alo, ahi, blo, bhi in cruncher.get_opcodes():
if tag == 'equal':
continue
print nicerange(alo, ahi) + tag[0] + nicerange(blo, bhi)
dump('<', a, alo, ahi)
if a and b:
print '---'
dump('>', b, blo, bhi)
assert s1==s2, "HTML Output Changed"
def check_xml(s1, s2):
s1 = normalize_xml(s1)
s2 = normalize_xml(s2)
assert s1==s2, "XML Output Changed"
def normalize_html(s):
s = re.sub(r"[ \t]+", " ", s)
s = re.sub(r"/>", ">", s)
return s
def normalize_xml(s):
s = re.sub(r"\s+", " ", s)
s = re.sub(r"(?s)\s+<", "<", s)
s = re.sub(r"(?s)>\s+", ">", s)
return s
import Zope.PageTemplate.tests
dir = os.path.dirname(Zope.PageTemplate.tests.__file__)
input_dir = os.path.join(dir, 'input')
output_dir = os.path.join(dir, 'output')
def read_input(filename):
filename = os.path.join(input_dir, filename)
return open(filename, 'r').read()
def read_output(filename):
filename = os.path.join(output_dir, filename)
return open(filename, 'r').read()