[CMF-checkins] SVN: CMF/trunk/C Merged CMF 1.5 branch r41634:41635 into the trunk.

Stefan H. Holek stefan at epy.co.at
Thu Feb 16 18:18:06 EST 2006


Log message for revision 41637:
  Merged CMF 1.5 branch r41634:41635 into the trunk.
  
  CMFCore.FSPythonScript: FSPythonScripts forgot to add __file__ to
  the script globals. This broke warnings.warn() when a stacklevel
  argument pointing into the script was passed (2).
  

Changed:
  U   CMF/trunk/CHANGES.txt
  U   CMF/trunk/CMFCore/FSPythonScript.py
  A   CMF/trunk/CMFCore/tests/fake_skins/fake_skin/test_warn.py
  U   CMF/trunk/CMFCore/tests/test_FSPythonScript.py

-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt	2006-02-16 22:54:35 UTC (rev 41636)
+++ CMF/trunk/CHANGES.txt	2006-02-16 23:18:06 UTC (rev 41637)
@@ -123,6 +123,10 @@
 
   Bug Fixes
 
+    - CMFCore.FSPythonScript: FSPythonScripts forgot to add __file__ to
+      the script globals. This broke warnings.warn() when a stacklevel
+      argument pointing into the script was passed (2).
+
     - CMFDefault setuphandlers: Disabled password encryption.
       'registeredNotify' and 'mailPassword' don't work with encrypted
       passwords.

Modified: CMF/trunk/CMFCore/FSPythonScript.py
===================================================================
--- CMF/trunk/CMFCore/FSPythonScript.py	2006-02-16 22:54:35 UTC (rev 41636)
+++ CMF/trunk/CMFCore/FSPythonScript.py	2006-02-16 23:18:06 UTC (rev 41637)
@@ -183,6 +183,7 @@
         new_globals = f.func_globals.copy()
         new_globals['__traceback_supplement__'] = (
             FSPythonScriptTracebackSupplement, self)
+        new_globals['__file__'] = self._filepath
         if bound_names:
             new_globals.update(bound_names)
         if f.func_defaults:

Copied: CMF/trunk/CMFCore/tests/fake_skins/fake_skin/test_warn.py (from rev 41635, CMF/branches/1.5/CMFCore/tests/fake_skins/fake_skin/test_warn.py)

Modified: CMF/trunk/CMFCore/tests/test_FSPythonScript.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_FSPythonScript.py	2006-02-16 22:54:35 UTC (rev 41636)
+++ CMF/trunk/CMFCore/tests/test_FSPythonScript.py	2006-02-16 23:18:06 UTC (rev 41637)
@@ -26,12 +26,14 @@
 from time import sleep
 
 from OFS.Folder import Folder
+from OFS.SimpleItem import SimpleItem
 from Products.StandardCacheManagers import RAMCacheManager
 
 from Products.CMFCore.FSPythonScript import FSPythonScript
 from Products.CMFCore.FSMetadata import FSMetadata
 from Products.CMFCore.tests.base.testcase import FSDVTest
 from Products.CMFCore.tests.base.testcase import SecurityTest
+from Products.CMFCore.tests.base.testcase import WarningInterceptor
 
 
 class FSPSMaker(FSDVTest):
@@ -236,11 +238,46 @@
         cps.write(_REPLACEMENT_TEXT)
         self.assertEqual(list(cps.getDiff()), _DIFF_TEXT.splitlines())
 
+
+class WarnMe(SimpleItem):
+    """Emits a UserWarning when called"""
+
+    def __init__(self, stacklevel):
+        self._stacklevel = stacklevel
+
+    def __call__(self):
+        import warnings
+        warnings.warn('foo', stacklevel=self._stacklevel)
+
+
+class FSPythonScriptWarningsTests(SecurityTest, FSPSMaker, WarningInterceptor):
+
+    def setUp( self ):
+        SecurityTest.setUp(self)
+        FSPSMaker.setUp(self)
+        self._trap_warning_output()
+
+    def tearDown(self):
+        self._free_warning_output()
+        FSPSMaker.tearDown(self)
+        SecurityTest.tearDown(self)
+
+    def testFSPSWarn(self):
+        self.root._setObject('warn_me', WarnMe(2))
+        self.root._setObject('warn1', self._makeOne('warn1', 'test_warn.py'))
+        # This used to raise an error:
+        #   File "/usr/local/python2.3/lib/python2.3/warnings.py", line 63, in warn_explicit
+        #     if module[-3:].lower() == ".py":
+        # TypeError: unsubscriptable object
+        self.root.warn1()
+
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(FSPythonScriptTests),
         unittest.makeSuite(FSPythonScriptCustomizationTests),
         unittest.makeSuite(CustomizedPythonScriptTests),
+        unittest.makeSuite(FSPythonScriptWarningsTests),
         ))
 
 if __name__ == '__main__':



More information about the CMF-checkins mailing list