[ZPT] CVS: Releases/Zope/lib/python/Products/PageTemplates/tests - testExpressions.py:1.9.6.1
Evan Simpson
evan@zope.com
Wed, 25 Sep 2002 19:20:10 -0400
Update of /cvs-repository/Releases/Zope/lib/python/Products/PageTemplates/tests
In directory cvs.zope.org:/tmp/cvs-serv20638/lib/python/Products/PageTemplates/tests
Modified Files:
Tag: Zope-2_6-branch
testExpressions.py
Log Message:
Merge TALES Expression fixes from trunk.
=== Releases/Zope/lib/python/Products/PageTemplates/tests/testExpressions.py 1.9 => 1.9.6.1 ===
--- Releases/Zope/lib/python/Products/PageTemplates/tests/testExpressions.py:1.9 Wed Aug 14 18:17:24 2002
+++ Releases/Zope/lib/python/Products/PageTemplates/tests/testExpressions.py Wed Sep 25 19:20:09 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,22 @@
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 test_suite():
return unittest.makeSuite(ExpressionTests)