[Zope-Checkins]
SVN: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/
cleanup
Andreas Jung
andreas at andreas-jung.com
Sun Dec 11 08:22:40 EST 2005
Log message for revision 40702:
cleanup
Changed:
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/batch.py
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/input/
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/output/
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testDTMLTests.py
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testExpressions.py
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testHTMLTests.py
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testTALES.py
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZRPythonExpr.py
D Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/util.py
-=-
Deleted: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/batch.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/batch.py 2005-12-11 13:09:25 UTC (rev 40701)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/batch.py 2005-12-11 13:22:40 UTC (rev 40702)
@@ -1,122 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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
-#
-##############################################################################
-
-######################################################################
-# Sequence batching support
-
-import util
-
-__allow_access_to_unprotected_subobjects__={'batch': 1}
-__roles__=None
-
-
-class batch(util.Base):
- """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
Deleted: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testDTMLTests.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testDTMLTests.py 2005-12-11 13:09:25 UTC (rev 40701)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testDTMLTests.py 2005-12-11 13:22:40 UTC (rev 40702)
@@ -1,143 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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 Products.PageTemplates.tests import util
-from Products.PageTemplates.PageTemplate import PageTemplate
-from Acquisition import Implicit
-from AccessControl import SecurityManager
-from AccessControl.SecurityManagement import noSecurityManager
-
-class AqPageTemplate(Implicit, PageTemplate):
- pass
-
-class UnitTestSecurityPolicy:
- """
- Stub out the existing security policy for unit testing purposes.
- """
- #
- # Standard SecurityPolicy interface
- #
- def validate( self
- , accessed=None
- , container=None
- , name=None
- , value=None
- , context=None
- , roles=None
- , *args
- , **kw):
- return 1
-
- def checkPermission( self, permission, object, context) :
- return 1
-
-class DTMLTests(unittest.TestCase):
-
- def setUp(self):
- self.t=(AqPageTemplate())
- self.policy = UnitTestSecurityPolicy()
- self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
- noSecurityManager() # Use the new policy.
-
- def tearDown(self):
- SecurityManager.setSecurityPolicy( self.oldPolicy )
- noSecurityManager() # Reset to old policy.
-
- 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 Products.PageTemplates.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()
-
Deleted: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testExpressions.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testExpressions.py 2005-12-11 13:09:25 UTC (rev 40701)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testExpressions.py 2005-12-11 13:22:40 UTC (rev 40702)
@@ -1,80 +0,0 @@
-import os, sys, unittest
-
-from Products.PageTemplates import Expressions
-from Products.PageTemplates.DeferExpr import LazyWrapper
-from Products.PageTemplates.DeferExpr import DeferWrapper
-
-class Dummy:
- __allow_access_to_unprotected_subobjects__ = 1
- def __call__(self):
- return 'dummy'
-
-class ExpressionTests(unittest.TestCase):
-
- def setUp(self):
- self.e = e = Expressions.getEngine()
- self.ec = e.getContext(
- one = 1,
- d = {'one': 1, 'b': 'b', '': 'blank', '_': 'under'},
- blank = '',
- dummy = Dummy()
- )
-
- def tearDown(self):
- del self.e, self.ec
-
- def testCompile(self):
- '''Test expression compilation'''
- e = self.e
- 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 testSimpleEval(self):
- '''Test simple expression evaluation'''
- ec = self.ec
- assert ec.evaluate('one') == 1
- assert ec.evaluate('d/one') == 1
- assert ec.evaluate('d/b') == 'b'
-
- def testRenderedEval(self):
- ec = self.ec
- assert ec.evaluate('dummy') == 'dummy'
-
- def testEval1(self):
- '''Test advanced expression evaluation 1'''
- ec = self.ec
- assert ec.evaluate('x | nothing') is None
- assert ec.evaluate('d/') == 'blank'
- assert ec.evaluate('d/_') == 'under'
- assert ec.evaluate('d/ | nothing') == 'blank'
- assert ec.evaluate('d/?blank') == 'blank'
-
- def testHybrid(self):
- '''Test hybrid path expressions'''
- ec = self.ec
- assert ec.evaluate('x | python:1+1') == 2
- assert ec.evaluate('x | python:int') == int
- assert ec.evaluate('x | string:x') == 'x'
- assert ec.evaluate('x | string:$one') == '1'
- assert ec.evaluate('x | not:exists:x')
-
- def testWrappers(self):
- """Test if defer and lazy are returning their wrappers
- """
- ec = self.ec
- defer = ec.evaluate('defer: b')
- lazy = ec.evaluate('lazy: b')
- self.failUnless(isinstance(defer, DeferWrapper))
- self.failUnless(isinstance(lazy, LazyWrapper))
-
-def test_suite():
- return unittest.makeSuite(ExpressionTests)
-
-if __name__=='__main__':
- main()
Deleted: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testHTMLTests.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testHTMLTests.py 2005-12-11 13:09:25 UTC (rev 40701)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testHTMLTests.py 2005-12-11 13:22:40 UTC (rev 40702)
@@ -1,164 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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 Products.PageTemplates.tests import util
-from Products.PageTemplates.PageTemplate import PageTemplate
-from Products.PageTemplates.GlobalTranslationService import \
- setGlobalTranslationService
-from AccessControl import SecurityManager
-from AccessControl.SecurityManagement import noSecurityManager
-
-from Acquisition import Implicit
-class AqPageTemplate(Implicit, PageTemplate):
- pass
-
-class Folder(util.Base):
- pass
-
-class TestTranslationService:
- def translate(self, domain, msgid, mapping=None, *args, **kw):
- maps = []
- if mapping is not None:
- # Get a deterministic, sorted representation of dicts.
- for k, v in mapping.items():
- maps.append('%s:%s' % (`k`, `v`))
- maps.sort()
- return "[%s](%s/{%s})" % (domain, msgid, ','.join(maps))
-
-
-class UnitTestSecurityPolicy:
- """
- Stub out the existing security policy for unit testing purposes.
- """
- #
- # Standard SecurityPolicy interface
- #
- def validate( self
- , accessed=None
- , container=None
- , name=None
- , value=None
- , context=None
- , roles=None
- , *args
- , **kw):
- return 1
-
- def checkPermission( self, permission, object, context) :
- return 1
-
-class HTMLTests(unittest.TestCase):
-
- def setUp(self):
- self.folder = f = Folder()
- f.laf = AqPageTemplate()
- f.t = AqPageTemplate()
- self.policy = UnitTestSecurityPolicy()
- self.oldPolicy = SecurityManager.setSecurityPolicy( self.policy )
- noSecurityManager() # Use the new policy.
-
- def tearDown(self):
- SecurityManager.setSecurityPolicy( self.oldPolicy )
- noSecurityManager() # Reset to old policy.
-
- def assert_expected(self, t, fname, *args, **kwargs):
- t.write(util.read_input(fname))
- assert not t._v_errors, 'Template errors: %s' % t._v_errors
- expect = util.read_output(fname)
- out = t(*args, **kwargs)
- util.check_html(expect, out)
-
- def assert_expected_unicode(self, t, fname, *args, **kwargs):
- t.write(util.read_input(fname))
- assert not t._v_errors, 'Template errors: %s' % t._v_errors
- expect = util.read_output(fname)
- expect = unicode(expect, 'utf8')
- out = t(*args, **kwargs)
- util.check_html(expect, out)
-
- 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):
- self.assert_expected(self.folder.laf, 'TeeShopLAF.html')
-
- def check2(self):
- self.folder.laf.write(util.read_input('TeeShopLAF.html'))
-
- self.assert_expected(self.folder.t, 'TeeShop2.html',
- getProducts=self.getProducts)
-
- def check3(self):
- self.folder.laf.write(util.read_input('TeeShopLAF.html'))
-
- self.assert_expected(self.folder.t, 'TeeShop1.html',
- getProducts=self.getProducts)
-
- def checkSimpleLoop(self):
- self.assert_expected(self.folder.t, 'Loop1.html')
-
- def checkFancyLoop(self):
- self.assert_expected(self.folder.t, 'Loop2.html')
-
- def checkGlobalsShadowLocals(self):
- self.assert_expected(self.folder.t, 'GlobalsShadowLocals.html')
-
- def checkStringExpressions(self):
- self.assert_expected(self.folder.t, 'StringExpression.html')
-
- def checkReplaceWithNothing(self):
- self.assert_expected(self.folder.t, 'CheckNothing.html')
-
- def checkWithXMLHeader(self):
- self.assert_expected(self.folder.t, 'CheckWithXMLHeader.html')
-
- def checkNotExpression(self):
- self.assert_expected(self.folder.t, 'CheckNotExpression.html')
-
- def checkPathNothing(self):
- self.assert_expected(self.folder.t, 'CheckPathNothing.html')
-
- def checkPathAlt(self):
- self.assert_expected(self.folder.t, 'CheckPathAlt.html')
-
- def checkBatchIteration(self):
- self.assert_expected(self.folder.t, 'CheckBatchIteration.html')
-
- def checkUnicodeInserts(self):
- self.assert_expected_unicode(self.folder.t, 'CheckUnicodeInserts.html')
-
- def checkI18nTranslate(self):
- self.assert_expected(self.folder.t, 'CheckI18nTranslate.html')
-
- def checkI18nTranslateHooked(self):
- old_ts = setGlobalTranslationService(TestTranslationService())
- self.assert_expected(self.folder.t, 'CheckI18nTranslateHooked.html')
- setGlobalTranslationService(old_ts)
-
-def test_suite():
- return unittest.makeSuite(HTMLTests, 'check')
-
-if __name__=='__main__':
- main()
-
Deleted: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testTALES.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testTALES.py 2005-12-11 13:09:25 UTC (rev 40701)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testTALES.py 2005-12-11 13:22:40 UTC (rev 40702)
@@ -1,133 +0,0 @@
-import os, sys, unittest
-
-from Products.PageTemplates import TALES
-from Products.PageTemplates.tests import harness1
-import string
-
-class DummyUnicodeExpr:
- '''Dummy expression type handler returning unicode'''
- def __init__(self, name, expr, engine):
- self._name = name
- self._expr = expr
- def __call__(self, econtext):
- return unicode(self._expr, 'latin1')
- def __repr__(self):
- return '<SimpleExpr %s %s>' % (self._name, `self._expr`)
-
-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)
- e.registerType('unicode', DummyUnicodeExpr)
- return 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 testContextUnicode(self):
- '''Test evaluateText on unicode-returning expressions'''
- se = self.getContext().evaluateText('unicode:\xe9')
- self.assertEqual(se, u'\xe9')
-
- 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__':
- unittest.main(defaultTest='test_suite')
Deleted: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZRPythonExpr.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZRPythonExpr.py 2005-12-11 13:09:25 UTC (rev 40701)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZRPythonExpr.py 2005-12-11 13:22:40 UTC (rev 40702)
@@ -1,48 +0,0 @@
-""" Unit tests for Products.PageTemplates.ZRPythonExpr
-
-$Id
-"""
-import unittest
-
-class MiscTests(unittest.TestCase):
-
- def test_call_with_ns_prefer_context_to_here(self):
- from Products.PageTemplates.ZRPythonExpr import call_with_ns
- context = ['context']
- here = ['here']
- request = {'request': 1}
- names = {'context' : context, 'here': here, 'request' : request}
- result = call_with_ns(lambda td: td.this, names)
- self.failUnless(result is context, result)
-
- def test_call_with_ns_no_context_or_here(self):
- from Products.PageTemplates.ZRPythonExpr import call_with_ns
- request = {'request': 1}
- names = {'request' : request}
- result = call_with_ns(lambda td: td.this, names)
- self.failUnless(result is None, result)
-
- def test_call_with_ns_no_request(self):
- from Products.PageTemplates.ZRPythonExpr import call_with_ns
- context = ['context']
- here = ['here']
- names = {'context' : context, 'here': here}
-
- def _find_request(td):
- ns = td._pop() # peel off 'ns'
- instance_dict = td._pop() # peel off InstanceDict
- request = td._pop()
- td._push(request)
- td._push(instance_dict)
- td._push(ns)
- return request
-
- result = call_with_ns(_find_request, names)
- self.assertEqual(result, {})
-
-def test_suite():
- return unittest.makeSuite(MiscTests)
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
-
Deleted: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/util.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/util.py 2005-12-11 13:09:25 UTC (rev 40701)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/util.py 2005-12-11 13:22:40 UTC (rev 40702)
@@ -1,118 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors. All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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
-#
-##############################################################################
-
-######################################################################
-# Utility facilities to aid setting things up.
-
-import os, sys, string, re
-
-from ExtensionClass import Base
-
-class Bruce(Base):
- __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(Base):
- __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(Base):
- __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 Products.PageTemplates.tests
-dir = os.path.dirname( Products.PageTemplates.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()
More information about the Zope-Checkins
mailing list