[Zope-CVS] CVS: Packages/pypes/pypes/tests - runtests.py:1.3 test_expression.py:1.2

Casey Duncan casey at zope.com
Sat Jan 31 00:23:32 EST 2004


Update of /cvs-repository/Packages/pypes/pypes/tests
In directory cvs.zope.org:/tmp/cvs-serv16271/tests

Modified Files:
	runtests.py test_expression.py 
Log Message:
Implement freeOperands method and simple expression __call__
make sure expression tests are run by runtests


=== Packages/pypes/pypes/tests/runtests.py 1.2 => 1.3 ===
--- Packages/pypes/pypes/tests/runtests.py:1.2	Tue Aug  5 00:27:51 2003
+++ Packages/pypes/pypes/tests/runtests.py	Sat Jan 31 00:23:31 2004
@@ -9,6 +9,7 @@
 from test_identity import *
 from test_event import *
 from test_graph import *
+from test_expression import *
 
 if __name__ == '__main__':
     unittest.main()


=== Packages/pypes/pypes/tests/test_expression.py 1.1 => 1.2 ===
--- Packages/pypes/pypes/tests/test_expression.py:1.1	Fri Jan 30 00:41:38 2004
+++ Packages/pypes/pypes/tests/test_expression.py	Sat Jan 31 00:23:31 2004
@@ -16,6 +16,8 @@
 $Id$"""
 
 import unittest
+from sets import Set
+from compiler import ast
 from pypes.tests.common import sort
 from pypes.expression import Expression
 
@@ -36,7 +38,31 @@
     
     def testExprNames(self):
         e = Expression('Yodel.a["hee"] == str(hoo)')
-        self.assertEqual(sort(e.names()), ['Yodel', 'hoo', 'str'])
+        self.assertEqual(e.names(), Set(['Yodel', 'hoo', 'str']))
+    
+    def testExprOneName(self):
+        e = Expression('x')
+        self.assertEqual(e.names(), Set(['x']))
+    
+    def testExprFreeOperands(self):
+        e = Expression('x.foo == 1 and y or len(z) in (2,3) and (x == y) < 1', 
+                       {'z':('a','b')})
+        free = e.freeOperands()
+        self.assertEqual(len(free), 3)
+        self.failUnless(isinstance(free[0], ast.Getattr))
+        self.failUnless(isinstance(free[1], ast.Name))
+        self.failUnless(isinstance(free[2], ast.Compare))
+    
+    def testExprCall(self):
+        e = Expression('x == 1 and y > x', {'y':2})
+        self.failUnless(e({'x':1}))
+        self.failIf(e({'x':2}))
+        self.failIf(e({'x':1, 'y':1}))
+    
+    def testExprCallRaises(self):
+        e = Expression('len(d) > 5')
+        d = []
+        self.assertRaises(NameError, e)
     
 class WhiteTestExpression(unittest.TestCase):
     """Whitebox expression tests"""
@@ -44,9 +70,9 @@
     def testExprGetsNamesAndValues(self):
         ns = {'tomorrow':1, 'today':0, 'yesterday':-1, 'lastweek':-7}
         e = Expression('yesterday < today < tomorrow', ns)
-        self.failIf(e._ns is ns)
+        self.failIf(e._bindings is ns)
         del ns['lastweek']
-        self.assertEqual(e._ns, ns)
+        self.assertEqual(e._bindings, ns)
 
 if __name__ == '__main__':
     unittest.main()




More information about the Zope-CVS mailing list