[ZPT] CVS: Releases/Zope/lib/python/Products/PageTemplates/tests - testExpressions.py:1.10

Evan Simpson evan@zope.com
Wed, 25 Sep 2002 18:57:56 -0400


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

Modified Files:
	testExpressions.py 
Log Message:
Fix Collector #581, with unit test.

Tidy up inconsistency use of getattr/guarded_getattr.


=== Releases/Zope/lib/python/Products/PageTemplates/tests/testExpressions.py 1.9 => 1.10 ===
--- 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 18:57:55 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)