[Zope3-checkins] CVS: Zope3/src/zope/pagetemplate/tests - __init__.py:1.2 batch.py:1.2 test_basictemplate.py:1.2 test_expressions.py:1.2 test_htmltests.py:1.2 test_tales.py:1.2 util.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:15:44 -0500


Update of /cvs-repository/Zope3/src/zope/pagetemplate/tests
In directory cvs.zope.org:/tmp/cvs-serv20790/src/zope/pagetemplate/tests

Added Files:
	__init__.py batch.py test_basictemplate.py test_expressions.py 
	test_htmltests.py test_tales.py util.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/pagetemplate/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:44 2002
+++ Zope3/src/zope/pagetemplate/tests/__init__.py	Wed Dec 25 09:15:13 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/pagetemplate/tests/batch.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:44 2002
+++ Zope3/src/zope/pagetemplate/tests/batch.py	Wed Dec 25 09:15:13 2002
@@ -0,0 +1,117 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+__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


=== Zope3/src/zope/pagetemplate/tests/test_basictemplate.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:44 2002
+++ Zope3/src/zope/pagetemplate/tests/test_basictemplate.py	Wed Dec 25 09:15:13 2002
@@ -0,0 +1,111 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import os
+import sys
+import unittest
+
+from zope.pagetemplate.tests import util
+from zope.pagetemplate.pagetemplate import PageTemplate
+
+class BasicTemplateTests(unittest.TestCase):
+
+    def setUp(self):
+        self.t = PageTemplate()
+
+    def test_if_in_var(self):
+        # DTML test 1: if, in, and var:
+        pass # for unittest
+        """
+        %(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(content=aa)
+        expect = util.read_output('dtml1a.html')
+
+        util.check_xml(expect, o)
+
+        aa = util.argv(())
+        o = self.t(content=aa)
+        expect = util.read_output('dtml1b.html')
+        util.check_xml(expect, o)
+
+    def test_batches_and_formatting(self):
+        # DTML test 3: batches and formatting:
+        pass # for unittest
+        """
+          <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(content=aa, batch=batch.batch(aa.args, 5))
+
+        expect = util.read_output('dtml3.html')
+        util.check_xml(expect, o)
+
+
+def test_suite():
+    return unittest.makeSuite(BasicTemplateTests)
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/pagetemplate/tests/test_expressions.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:44 2002
+++ Zope3/src/zope/pagetemplate/tests/test_expressions.py	Wed Dec 25 09:15:13 2002
@@ -0,0 +1,85 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import os, sys, unittest
+
+from zope.pagetemplate.engine import Engine
+
+class Data:
+
+    def __init__(self, **kw):
+        self.__dict__.update(kw)
+
+    def __repr__(self): return self.name
+
+
+def dict(**kw):
+    return kw
+
+
+class ExpressionTests(unittest.TestCase):
+
+    def testCompile(self):
+        # Test expression compilation
+        context = Data(
+            vars = dict(
+              x = Data(
+                 name = 'xander',
+                 y = Data(
+                    name = 'yikes',
+                    z = Data(name = 'zope')
+                    )
+                 ),
+              y = Data(z = 3),
+              b = 'boot',
+              B = 2,
+              )
+            )
+
+
+        engine = Engine
+
+        expr = engine.compile('x')
+        self.assertEqual(expr(context), context.vars['x'])
+
+        expr = engine.compile('x/y')
+        self.assertEqual(expr(context), context.vars['x'].y)
+
+        expr = engine.compile('x/y/z')
+        self.assertEqual(expr(context), context.vars['x'].y.z)
+
+        expr = engine.compile('path:a|b|c/d/e')
+        self.assertEqual(expr(context), 'boot')
+
+        expr = engine.compile('string:Fred')
+        self.assertEqual(expr(context), 'Fred')
+
+        expr = engine.compile('string:A$B')
+        self.assertEqual(expr(context), 'A2')
+
+        expr = engine.compile('string:a ${x/y} b ${y/z} c')
+        self.assertEqual(expr(context), 'a yikes b 3 c')
+
+        expr = engine.compile('python: 2 + 2')
+        self.assertEqual(expr(context), 4)
+
+        expr = engine.compile('python: 2 \n+\n 2\n')
+        self.assertEqual(expr(context), 4)
+
+
+def test_suite():
+    return unittest.makeSuite(ExpressionTests)
+
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/pagetemplate/tests/test_htmltests.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:44 2002
+++ Zope3/src/zope/pagetemplate/tests/test_htmltests.py	Wed Dec 25 09:15:13 2002
@@ -0,0 +1,128 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import unittest
+
+from zope.pagetemplate.tests import util
+from zope.pagetemplate.pagetemplate import PageTemplate
+
+
+class Folder:
+    context = property(lambda self: self)
+
+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 test_1(self):
+        laf = self.folder.laf
+        laf.write(util.read_input('teeshoplaf.html'))
+        expect = util.read_output('teeshoplaf.html')
+        util.check_html(expect, laf())
+
+    def test_2(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(laf = self.folder.laf, getProducts = self.getProducts)
+        util.check_html(expect, out)
+
+
+    def test_3(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(laf = self.folder.laf, getProducts = self.getProducts)
+        util.check_html(expect, out)
+
+    def test_SimpleLoop(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 test_GlobalsShadowLocals(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 test_StringExpressions(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 test_ReplaceWithNothing(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 test_WithXMLHeader(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 test_NotExpression(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 test_PathNothing(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 test_PathAlt(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)
+
+if __name__=='__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/pagetemplate/tests/test_tales.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:44 2002
+++ Zope3/src/zope/pagetemplate/tests/test_tales.py	Wed Dec 25 09:15:13 2002
@@ -0,0 +1,157 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import os
+import sys
+import unittest
+
+from zope.pagetemplate import tales
+
+
+class TALESTests(unittest.TestCase):
+
+    def testIterator0(self):
+        # Test sample Iterator class
+        context = Harness()
+        it = tales.Iterator('name', (), context)
+        assert not it.next(), "Empty iterator"
+        context._complete_()
+
+    def testIterator1(self):
+        # Test sample Iterator class
+        context = Harness()
+        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 = Harness()
+        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.ExpressionEngine()
+        e.registerType('simple', tales.SimpleExpr)
+        assert e.getTypes()['simple'] == tales.SimpleExpr
+
+    def testRegisterTypeUnique(self):
+        # Test expression type registration uniqueness
+        e = tales.ExpressionEngine()
+        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.ExpressionEngine()
+        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.ExpressionEngine()
+        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.ExpressionEngine().getContext()
+        tales.ExpressionEngine().getContext(v=1)
+        tales.ExpressionEngine().getContext(x=1, y=2)
+
+    def getContext(self, **kws):
+        e = tales.ExpressionEngine()
+        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()
+
+
+class Harness:
+    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"
+
+
+def test_suite():
+    return unittest.makeSuite(TALESTests)
+
+
+if __name__ == '__main__':
+    unittest.TextTestRunner().run(test_suite())


=== Zope3/src/zope/pagetemplate/tests/util.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:15:44 2002
+++ Zope3/src/zope/pagetemplate/tests/util.py	Wed Dec 25 09:15:13 2002
@@ -0,0 +1,107 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import os
+import re
+import sys
+
+
+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 ininstance(index, int) and (index < 0 or index > 6):
+            raise IndexError, index
+        return self
+    isDocTemp = 0
+    def __getattr__(self,name):
+        if name.startswith('_'):
+            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
+
+    context = property(lambda self: self)
+
+def nicerange(lo, hi):
+    if hi <= lo+1:
+        return str(lo+1)
+    else:
+        return "%d,%d" % (lo+1, hi)
+
+def dump(tag, x, lo, hi):
+    for i in xrange(lo, hi):
+        print '%s %s' % (tag, x[i]),
+
+def check_html(s1, s2):
+    s1 = normalize_html(s1)
+    s2 = normalize_html(s2)
+    assert s1==s2, (s1, s2, "HTML Output Changed")
+
+def check_xml(s1, s2):
+    s1 = normalize_xml(s1)
+    s2 = normalize_xml(s2)
+    assert s1==s2, ("XML Output Changed:\n%s\n\n%s" % (s1, s2))
+
+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()