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

Stefan H. Holek stefan at epy.co.at
Thu Feb 16 17:54:35 EST 2006


Log message for revision 41636:
  Merged CMF 1.5 branch r41634:41635 into 1.6 branch.
  
  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/branches/1.6/CHANGES.txt
  U   CMF/branches/1.6/CMFCore/FSPythonScript.py
  A   CMF/branches/1.6/CMFCore/tests/fake_skins/fake_skin/test_warn.py
  U   CMF/branches/1.6/CMFCore/tests/test_FSPythonScript.py

-=-
Modified: CMF/branches/1.6/CHANGES.txt
===================================================================
--- CMF/branches/1.6/CHANGES.txt	2006-02-16 22:47:15 UTC (rev 41635)
+++ CMF/branches/1.6/CHANGES.txt	2006-02-16 22:54:35 UTC (rev 41636)
@@ -2,6 +2,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).
+
     - DCWorkflow.exportimport: Workflows managing no permissions at all 
       could make the DCWorkflow workflow exporter fail.
       (http://www.zope.org/Collectors/CMF/397)

Modified: CMF/branches/1.6/CMFCore/FSPythonScript.py
===================================================================
--- CMF/branches/1.6/CMFCore/FSPythonScript.py	2006-02-16 22:47:15 UTC (rev 41635)
+++ CMF/branches/1.6/CMFCore/FSPythonScript.py	2006-02-16 22:54:35 UTC (rev 41636)
@@ -148,6 +148,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/branches/1.6/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/branches/1.6/CMFCore/tests/test_FSPythonScript.py
===================================================================
--- CMF/branches/1.6/CMFCore/tests/test_FSPythonScript.py	2006-02-16 22:47:15 UTC (rev 41635)
+++ CMF/branches/1.6/CMFCore/tests/test_FSPythonScript.py	2006-02-16 22:54:35 UTC (rev 41636)
@@ -12,12 +12,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):
@@ -143,10 +145,44 @@
         FSPSMaker.tearDown(self)
 
 
+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 TestSuite((
         makeSuite(FSPythonScriptTests),
         makeSuite(FSPythonScriptCustomizationTests),
+        makeSuite(FSPythonScriptWarningsTests),
         ))
 
 if __name__ == '__main__':



More information about the CMF-checkins mailing list