[Zope3-checkins] CVS: Zope3/src/zope/app/interpreter/tests - interpreter.zcml:1.1.2.1 test_directives.py:1.1.2.1 test_pythoninterpreter.py:1.1.2.1 test_service.py:1.1.2.1

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Aug 21 01:02:18 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/interpreter/tests
In directory cvs.zope.org:/tmp/cvs-serv3254/app/interpreter/tests

Added Files:
      Tag: srichter-inlinepython-branch
	interpreter.zcml test_directives.py test_pythoninterpreter.py 
	test_service.py 
Log Message:
Wrote tests for the interpreter service and the PythonInterpreter.

Fixed bug in secure interpreter in zope.security.

Removed some tests from test_talinterpreter, since it really tested Python
stuff, not TAL specific functionality.


=== Added File Zope3/src/zope/app/interpreter/tests/interpreter.zcml ===
<configure 
    xmlns="http://namespaces.zope.org/zope"
    xmlns:code="http://namespaces.zope.org/code">

  <include package="zope.app.interpreter" file="meta.zcml" />

  <code:registerInterpreter
      type="text/server-test"
      component=".test_directives.TestInterpreter" />

</configure>


=== Added File Zope3/src/zope/app/interpreter/tests/test_directives.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
#
##############################################################################
"""Test the workflow ZCML namespace directives.

$Id: test_directives.py,v 1.1.2.1 2003/08/21 04:02:17 srichter Exp $
"""
import unittest

from zope.app.interfaces.interpreter import IInterpreter
from zope.app.interpreter import interpreterService
from zope.app.tests.placelesssetup import PlacelessSetup
from zope.configuration import xmlconfig
from zope.interface import implements

from zope.app.interpreter import tests 

class TestInterpreter:
    implements(IInterpreter)

TestInterpreter = TestInterpreter()

class DirectivesTest(PlacelessSetup, unittest.TestCase):

    def setUp(self):
        PlacelessSetup.setUp(self)
        self.context = xmlconfig.file("interpreter.zcml", tests)

    def testRegisterInterpreter(self):
        self.assertEqual(
            interpreterService.getInterpreter('text/server-test'),
            TestInterpreter)

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(DirectivesTest),
        ))

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


=== Added File Zope3/src/zope/app/interpreter/tests/test_pythoninterpreter.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
#
##############################################################################
"""Test the workflow ZCML namespace directives.

$Id: test_pythoninterpreter.py,v 1.1.2.1 2003/08/21 04:02:17 srichter Exp $
"""
import unittest

from zope.app.interfaces.interpreter import IInterpreter
from zope.app.interpreter.python import PythonInterpreter
from zope.exceptions import ForbiddenAttribute
from zope.interface.verify import verifyObject

class PythonInterpreterTest(unittest.TestCase):

    def _check(self, code, output, raw=False):
        if raw:
            func = PythonInterpreter.evaluateRawCode
        else:
            func = PythonInterpreter.evaluate
        self.globals = {}
        self.assertEqual(func(code, self.globals), output)

    def test_verifyInterface(self):
        self.assert_(verifyObject(IInterpreter, PythonInterpreter))

    def test_simple(self):
        self._check('print "hello"', 'hello\n')
        self._check('print "hello"', 'hello\n', True)

    def test_indented(self):
        self._check('\n  print "hello"\n', 'hello\n', True)

    def test_multi_line(self):
        code = ('print "hello"\n'
                'print "world"\n')
        self._check(code, 'hello\nworld\n')
        self._check(code, 'hello\nworld\n', True)
        code = ('  print "hello"\n'
                '  print "world"\n')
        self._check(code, 'hello\nworld\n', True)

    def test_variable_assignment(self):
        code = ('x = "hello"\n'
                'print x')
        self._check(code, 'hello\n')
        self._check(code, 'hello\n', True)

    def test_local_variable_assignment(self):
        code = ('x = "hello"\n')
        self._check(code, '')
        self.assert_('x' not in self.globals.keys())

    def test_global_variable_assignment(self):
        code = ('global x\n'
                'x = "hello"\n')
        self._check(code, '')
        self.assertEqual(self.globals['x'], 'hello')

    def test_wrapped_by_html_comment(self):
        self._check('<!-- print "hello" -->', 'hello\n', True)
        self._check('<!--\nprint "hello"\n -->', 'hello\n', True)
        self._check('<!--\n  print "hello"\n -->', 'hello\n', True)

    def test_forbidden_attribute(self):
        code = ('import sys\n'
                'print sys.path\n')
        self.assertRaises(ForbiddenAttribute,
                          PythonInterpreter.evaluateRawCode, code, {})


def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(PythonInterpreterTest),
        ))

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


=== Added File Zope3/src/zope/app/interpreter/tests/test_service.py ===
##############################################################################
#
# Copyright (c) 2001, 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.
#
##############################################################################
"""Test the workflow ZCML namespace directives.

$Id: test_service.py,v 1.1.2.1 2003/08/21 04:02:17 srichter Exp $
"""
import unittest

from zope.app.interfaces.interpreter import IInterpreter, IInterpreterService
from zope.app.interpreter import GlobalInterpreterService
from zope.interface import implements
from zope.interface.verify import verifyClass

class TestInterpreter:
    implements(IInterpreter)

TestInterpreter = TestInterpreter()

class ServiceTest(unittest.TestCase):

    def setUp(self):
        self.service = GlobalInterpreterService()
        self.service.provideInterpreter('text/server-test', TestInterpreter)

    def test_verifyInterface(self):
        self.assert_(verifyClass(IInterpreterService,
                                 GlobalInterpreterService))

    def test_getInterpreter(self):
        self.assertEqual(
            self.service.getInterpreter('text/server-test'),
            TestInterpreter)
        self.assertRaises(KeyError, self.service.getInterpreter,
                          'text/server-test2')

    def test_queryInterpreter(self):
        self.assertEqual(
            self.service.queryInterpreter('text/server-test'),
            TestInterpreter)
        self.assertEqual(
            self.service.queryInterpreter('text/server-test2', 'foo'),
            'foo')

def test_suite():
    return unittest.TestSuite((
        unittest.makeSuite(ServiceTest),
        ))

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




More information about the Zope3-Checkins mailing list