[Zope-CVS] CVS: Packages/pypes/pypes/tests - test_expression.py:1.7

Casey Duncan casey at zope.com
Tue Apr 13 00:15:30 EDT 2004


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

Modified Files:
	test_expression.py 
Log Message:
change freeOperands() to return Expressions rather than AST nodes
Add alternate constructor fromAstNode() to create expression from AST node rather than a string.
Expressions are now compiled from their AST. Expression.__call__ evals the compiled code instead of the string


=== Packages/pypes/pypes/tests/test_expression.py 1.6 => 1.7 ===
--- Packages/pypes/pypes/tests/test_expression.py:1.6	Wed Mar 10 16:14:27 2004
+++ Packages/pypes/pypes/tests/test_expression.py	Tue Apr 13 00:15:28 2004
@@ -29,6 +29,12 @@
         from pypes.interfaces import IExpression
         self.failUnless(verifyObject(IExpression, Expression('x')))
     
+    def testExprFromAst(self):
+        # Test alternate constructor
+        ast = parse('sin(1 / x)', mode='eval')
+        e = Expression.fromAstNode(ast, {})
+        self.assertEqual(e.names(), Set(['sin', 'x']))
+    
     def testExprParses(self):
         Expression('x')
         self.assertRaises(SyntaxError, Expression, 'beautiful me')
@@ -63,9 +69,9 @@
                        {'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))
+        self.assertEqual(free[0].names(), free[0].freeNames(), Set(['x']))
+        self.assertEqual(free[1].names(), free[1].freeNames(), Set(['y']))
+        self.assertEqual(free[2].names(), free[2].freeNames(), Set(['x', 'y']))
     
     def testExprCall(self):
         e = Expression('x == 1 and y > x', {'y':2})




More information about the Zope-CVS mailing list