Commit 530dd5f7 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 e274b646
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
"""Python Scripts Product """Python Scripts Product
This product provides support for Script objects containing restricted This product provides support for Script objects containing restricted
Python code. Python code.
$Id$
""" """
__version__='$Revision: 1.56 $'[11:-2]
from logging import getLogger from logging import getLogger
import marshal import marshal
...@@ -273,7 +273,14 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -273,7 +273,14 @@ class PythonScript(Script, Historical, Cacheable):
g = get_safe_globals() g = get_safe_globals()
g['_getattr_'] = guarded_getattr g['_getattr_'] = guarded_getattr
g['__debug__'] = __debug__ 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 = {} l = {}
exec code in g, l exec code in g, l
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
import os, sys, unittest, warnings import os, unittest, warnings
from Products.PythonScripts.PythonScript import PythonScript from Products.PythonScripts.PythonScript import PythonScript
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
...@@ -295,21 +295,24 @@ class TestPythonScriptGlobals(PythonScriptTestBase, WarningInterceptor): ...@@ -295,21 +295,24 @@ class TestPythonScriptGlobals(PythonScriptTestBase, WarningInterceptor):
def test__name__(self): def test__name__(self):
f = self._filePS('class.__name__') 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): def test_filepath(self):
# This test is meant to raise a deprecation warning. # This test is meant to raise a deprecation warning.
# It used to fail mysteriously instead. # It used to fail mysteriously instead.
self._trap_warning_output() def warnMe(message):
warnings.warn(message, stacklevel=2)
try:
f = self._filePS('filepath') f = self._filePS('filepath')
self.assertEqual(f(), [0]) self._trap_warning_output()
results = f._exec({'container': warnMe}, (), {})
self._free_warning_output() self._free_warning_output()
else: warning = self._our_stderr_stream.getvalue()
def test_filepath(self): self.failUnless('UserWarning: foo' in warning)
# On Python 2.6, this now raises a TypeError. except TypeError, e:
f = self._filePS('filepath') self.fail(e)
self.assertRaises(TypeError, f)
class PythonScriptInterfaceConformanceTests(unittest.TestCase): class PythonScriptInterfaceConformanceTests(unittest.TestCase):
......
return range(1.0) return container('foo')
# This test is meant to raise a deprecation warning. # 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