[Zope3-checkins] CVS: Zope3/src/zope/app/interpreter/tests -
__init__.py:1.2 interpreter.zcml:1.2 test_directives.py:1.2
test_pythoninterpreter.py:1.2 test_service.py:1.2
Stephan Richter
srichter at cosmos.phy.tufts.edu
Thu Aug 21 11:19:56 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/interpreter/tests
In directory cvs.zope.org:/tmp/cvs-serv8485/src/zope/app/interpreter/tests
Added Files:
__init__.py interpreter.zcml test_directives.py
test_pythoninterpreter.py test_service.py
Log Message:
Final HEAD checkin of "Inline Code Support in TAL". For detailed messages
during the development, see "srichter-inlinepython-branch". I tested the
code with both, Python 2.2.3 and Python 2.3 and all works fine.
Here an example of what you can do:
<script type="text/server-python">
print "Hello World!"
</script>
and
<p tal:script="text/server-python">
print "Hello World!"
</p>
A more elaborate example would be:
<html><body>
<script type="text/server-python">
global x
x = "Hello World!"
</script>
<b tal:content="x" />
</body></html>
This support is currently only available in "Templated Pages" after you
activate the hook using the "Inline Code" screen.
=== Zope3/src/zope/app/interpreter/tests/__init__.py 1.1 => 1.2 ===
=== Zope3/src/zope/app/interpreter/tests/interpreter.zcml 1.1 => 1.2 ===
--- /dev/null Thu Aug 21 10:19:56 2003
+++ Zope3/src/zope/app/interpreter/tests/interpreter.zcml Thu Aug 21 10:19:25 2003
@@ -0,0 +1,11 @@
+<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>
=== Zope3/src/zope/app/interpreter/tests/test_directives.py 1.1 => 1.2 ===
--- /dev/null Thu Aug 21 10:19:56 2003
+++ Zope3/src/zope/app/interpreter/tests/test_directives.py Thu Aug 21 10:19:25 2003
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# 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$
+"""
+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()
=== Zope3/src/zope/app/interpreter/tests/test_pythoninterpreter.py 1.1 => 1.2 ===
--- /dev/null Thu Aug 21 10:19:56 2003
+++ Zope3/src/zope/app/interpreter/tests/test_pythoninterpreter.py Thu Aug 21 10:19:25 2003
@@ -0,0 +1,89 @@
+##############################################################################
+#
+# 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$
+"""
+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()
=== Zope3/src/zope/app/interpreter/tests/test_service.py 1.1 => 1.2 ===
--- /dev/null Thu Aug 21 10:19:56 2003
+++ Zope3/src/zope/app/interpreter/tests/test_service.py Thu Aug 21 10:19:25 2003
@@ -0,0 +1,61 @@
+##############################################################################
+#
+# 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$
+"""
+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