[Zope-Checkins] SVN: Zope/branches/Zope-2_8-branch/ Suppress expected DeprecationWarning output in test.

Tres Seaver tseaver at palladion.com
Tue Nov 22 13:15:37 EST 2005


Log message for revision 40327:
  Suppress expected DeprecationWarning output in test.

Changed:
  U   Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
  U   Zope/branches/Zope-2_8-branch/lib/python/Products/PythonScripts/tests/testPythonScript.py

-=-
Modified: Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
===================================================================
--- Zope/branches/Zope-2_8-branch/doc/CHANGES.txt	2005-11-22 18:10:16 UTC (rev 40326)
+++ Zope/branches/Zope-2_8-branch/doc/CHANGES.txt	2005-11-22 18:15:37 UTC (rev 40327)
@@ -44,6 +44,11 @@
         warnings and converted ZGadflyDA/__init__.py and
         ZSQLMethods/__init__.py to use registerClass instead.
 
+    Other
+
+      - Suppressed output of deprecation warning in 'filepath' test
+        for PythonScripts.
+
   Zope 2.8.4 (2005/10/26)
 
     Bugs Fixed

Modified: Zope/branches/Zope-2_8-branch/lib/python/Products/PythonScripts/tests/testPythonScript.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Products/PythonScripts/tests/testPythonScript.py	2005-11-22 18:10:16 UTC (rev 40326)
+++ Zope/branches/Zope-2_8-branch/lib/python/Products/PythonScripts/tests/testPythonScript.py	2005-11-22 18:15:37 UTC (rev 40327)
@@ -25,6 +25,30 @@
     if not here:
         here = os.getcwd()
 
+class WarningInterceptor:
+
+    _old_stderr = None
+    _our_stderr_stream = None
+
+    def _trap_warning_output( self ):
+
+        if self._old_stderr is not None:
+            return
+
+        import sys
+        from StringIO import StringIO
+
+        self._old_stderr = sys.stderr
+        self._our_stderr_stream = sys.stderr = StringIO()
+
+    def _free_warning_output( self ):
+
+        if self._old_stderr is None:
+            return
+
+        import sys
+        sys.stderr = self._old_stderr
+
 # Test Classes
 
 def readf(name):
@@ -219,7 +243,7 @@
                 f = self._newPS(defn + "\n" + asn % name)
                 self.assertRaises(TypeError, f)
 
-class TestPythonScriptGlobals(PythonScriptTestBase):
+class TestPythonScriptGlobals(PythonScriptTestBase, WarningInterceptor):
     def _exec(self, script, bound_names=None, args=None, kws=None):
         if args is None:
             args = ()
@@ -241,8 +265,10 @@
     def test_filepath(self):
         # This test is meant to raise a deprecation warning.
         # It used to fail mysteriously instead.
+        self._trap_warning_output()
         f = self._filePS('filepath')
         self.assertEqual(f(), [0])
+        self._free_warning_output()
 
 def test_suite():
     suite = unittest.TestSuite()



More information about the Zope-Checkins mailing list