Commit 06e9faa4 authored by 's avatar

- fixed test_filepath for Python 2.6

- fixed the issue shown by test_filepath (changed the initial function __name__ to 'script')
- adjusted test__name__
parent 06db7cd8
......@@ -20,6 +20,8 @@ Features Added
Bugs Fixed
++++++++++
- PythonScript: Fixed small Python 2.6 compatibility issue.
- mkzopeinstance: Made instance scripts more suitable for egg based installs.
If you are using a customized skel, it has to be updated.
......
......@@ -7,16 +7,16 @@
# 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
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Python Scripts Product
This product provides support for Script objects containing restricted
Python code.
$Id$
"""
__version__='$Revision: 1.56 $'[11:-2]
from logging import getLogger
import marshal
......@@ -273,7 +273,14 @@ class PythonScript(Script, Historical, Cacheable):
g = get_safe_globals()
g['_getattr_'] = guarded_getattr
g['__debug__'] = __debug__
g['__name__'] = None
# it doesn't really matter what __name__ is, *but*
# - we need a __name__
# (see testPythonScript.TestPythonScriptGlobals.test__name__)
# - it should not contain a period, so we can't use the id
# (see https://bugs.launchpad.net/zope2/+bug/142731/comments/4)
# - with Python 2.6 it should not be None
# (see testPythonScript.TestPythonScriptGlobals.test_filepath)
g['__name__'] = 'script'
l = {}
exec code in g, l
......
......@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import os, sys, unittest, warnings
import os, unittest, warnings
from Products.PythonScripts.PythonScript import PythonScript
from AccessControl.SecurityManagement import newSecurityManager
......@@ -295,21 +295,24 @@ class TestPythonScriptGlobals(PythonScriptTestBase, WarningInterceptor):
def test__name__(self):
f = self._filePS('class.__name__')
self.assertEqual(f(), ("'foo'>", "'string'"))
self.assertEqual(f(), ("'script.foo'>", "'string'"))
if sys.version_info < (2, 6):
def test_filepath(self):
# This test is meant to raise a deprecation warning.
# It used to fail mysteriously instead.
self._trap_warning_output()
def test_filepath(self):
# This test is meant to raise a deprecation warning.
# It used to fail mysteriously instead.
def warnMe(message):
warnings.warn(message, stacklevel=2)
try:
f = self._filePS('filepath')
self.assertEqual(f(), [0])
self._trap_warning_output()
results = f._exec({'container': warnMe}, (), {})
self._free_warning_output()
else:
def test_filepath(self):
# On Python 2.6, this now raises a TypeError.
f = self._filePS('filepath')
self.assertRaises(TypeError, f)
warning = self._our_stderr_stream.getvalue()
self.failUnless('UserWarning: foo' in warning)
except TypeError, e:
self.fail(e)
class PythonScriptInterfaceConformanceTests(unittest.TestCase):
......
return range(1.0)
return container('foo')
# This test is meant to raise a deprecation warning.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment