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

Casey Duncan casey at zope.com
Fri Jan 30 00:41:38 EST 2004


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

Added Files:
	test_expression.py 
Log Message:
After further thought and discussion, switch to a parsed-string based expression scheme rather than a magic expresser object. There were too many vagarities and limitations with the latter to make it practical. String expressions will allow any desired interpretation of operators, without any real loss of transparency or function in the end.


=== Added File Packages/pypes/pypes/tests/test_expression.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Expression tests

$Id: test_expression.py,v 1.1 2004/01/30 05:41:38 caseman Exp $"""

import unittest
from pypes.tests.common import sort
from pypes.expression import Expression

class TestExpression(unittest.TestCase):
    """Blackbox expression tests"""
    
    def testExprParses(self):
        Expression('x')
        self.assertRaises(SyntaxError, Expression, 'beautiful me')
        
    def testExprStrAndRepr(self):
        s = 'yum + yum'
        self.assertEqual(str(Expression(s)), "Expression('%s')" % s)
        self.assertEqual(repr(Expression(s)), "Expression('%s')" % s)
    
    def testExprWithStatementsRaises(self):
        self.assertRaises(SyntaxError, Expression, 'def x(): pass')
    
    def testExprNames(self):
        e = Expression('Yodel.a["hee"] == str(hoo)')
        self.assertEqual(sort(e.names()), ['Yodel', 'hoo', 'str'])
    
class WhiteTestExpression(unittest.TestCase):
    """Whitebox expression tests"""
    
    def testExprGetsNamesAndValues(self):
        ns = {'tomorrow':1, 'today':0, 'yesterday':-1, 'lastweek':-7}
        e = Expression('yesterday < today < tomorrow', ns)
        self.failIf(e._ns is ns)
        del ns['lastweek']
        self.assertEqual(e._ns, ns)

if __name__ == '__main__':
    unittest.main()




More information about the Zope-CVS mailing list