[ZPT] CVS: Zope/lib/python/Products/PageTemplates/tests - __init__.py:1.2.4.1 testDTMLTests.py:1.7.4.1 testExpressions.py:1.9.4.1 testTALES.py:1.4.4.2

Chris McDonough chrism@zope.com
Sat, 28 Sep 2002 21:41:04 -0400


Update of /cvs-repository/Zope/lib/python/Products/PageTemplates/tests
In directory cvs.zope.org:/tmp/cvs-serv16902/lib/python/Products/PageTemplates/tests

Modified Files:
      Tag: chrism-install-branch
	__init__.py testDTMLTests.py testExpressions.py testTALES.py 
Log Message:
Merge chrism-install-branch with head.  Apologies for the spew.


=== Zope/lib/python/Products/PageTemplates/tests/__init__.py 1.2 => 1.2.4.1 ===
--- Zope/lib/python/Products/PageTemplates/tests/__init__.py:1.2	Wed Aug 14 18:17:24 2002
+++ Zope/lib/python/Products/PageTemplates/tests/__init__.py	Sat Sep 28 21:40:33 2002
@@ -34,3 +34,4 @@
         assert aargs == args, "Harness method arguments"
         assert akwargs == kwargs, "Harness method keyword args"
         return result
+    


=== Zope/lib/python/Products/PageTemplates/tests/testDTMLTests.py 1.7 => 1.7.4.1 ===
--- Zope/lib/python/Products/PageTemplates/tests/testDTMLTests.py:1.7	Wed Aug 14 18:17:24 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testDTMLTests.py	Sat Sep 28 21:40:33 2002
@@ -140,3 +140,4 @@
 
 if __name__=='__main__':
     main()
+


=== Zope/lib/python/Products/PageTemplates/tests/testExpressions.py 1.9 => 1.9.4.1 ===
--- Zope/lib/python/Products/PageTemplates/tests/testExpressions.py:1.9	Wed Aug 14 18:17:24 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testExpressions.py	Sat Sep 28 21:40:33 2002
@@ -4,9 +4,20 @@
 
 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 = '',
+            )
+
+    def tearDown(self):
+        del self.e, self.ec
+
     def testCompile(self):
         '''Test expression compilation'''
-        e = Expressions.getEngine()
+        e = self.e
         for p in ('x', 'x/y', 'x/y/z'):
             e.compile(p)
         e.compile('path:a|b|c/d/e')
@@ -15,6 +26,31 @@
         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 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 test_suite():
     return unittest.makeSuite(ExpressionTests)


=== Zope/lib/python/Products/PageTemplates/tests/testTALES.py 1.4.4.1 => 1.4.4.2 ===
--- Zope/lib/python/Products/PageTemplates/tests/testTALES.py:1.4.4.1	Tue Sep  3 03:43:46 2002
+++ Zope/lib/python/Products/PageTemplates/tests/testTALES.py	Sat Sep 28 21:40:33 2002
@@ -4,6 +4,16 @@
 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):
@@ -77,6 +87,7 @@
     def getContext(self, **kws):
         e = TALES.Engine()
         e.registerType('simple', TALES.SimpleExpr)
+        e.registerType('unicode', DummyUnicodeExpr)
         return apply(e.getContext, (), kws)
 
     def testContext0(self):
@@ -84,6 +95,11 @@
         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'''