[Checkins] SVN: Zope/trunk/ Testing.ZopeTestCase: Include a copy of ZODB.tests.warnhook to silence a DeprecationWarning under Python 2.6.

Stefan H. Holek stefan at epy.co.at
Wed May 13 13:19:10 EDT 2009


Log message for revision 99895:
  Testing.ZopeTestCase: Include a copy of ZODB.tests.warnhook to silence a DeprecationWarning under Python 2.6.
  

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/Testing/ZopeTestCase/__init__.py
  A   Zope/trunk/src/Testing/ZopeTestCase/warnhook.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst	2009-05-13 17:18:20 UTC (rev 99894)
+++ Zope/trunk/doc/CHANGES.rst	2009-05-13 17:19:09 UTC (rev 99895)
@@ -16,6 +16,9 @@
 
 - Launchpad #374719: introducing new ZPublisher events:
   PubStart, PubSuccess, PubFailure, PubAfterTraversal and PubBeforeCommit.
+
+- Testing.ZopeTestCase: Include a copy of ZODB.tests.warnhook to silence
+  a DeprecationWarning under Python 2.6.
   
 Bugs Fixed
 ++++++++++

Modified: Zope/trunk/src/Testing/ZopeTestCase/__init__.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/__init__.py	2009-05-13 17:18:20 UTC (rev 99894)
+++ Zope/trunk/src/Testing/ZopeTestCase/__init__.py	2009-05-13 17:19:09 UTC (rev 99895)
@@ -43,7 +43,7 @@
 from base import app
 from base import close
 
-from ZODB.tests.warnhook import WarningsHook
+from warnhook import WarningsHook
 from unittest import main
 
 from zopedoctest import ZopeDocTestSuite

Added: Zope/trunk/src/Testing/ZopeTestCase/warnhook.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/warnhook.py	                        (rev 0)
+++ Zope/trunk/src/Testing/ZopeTestCase/warnhook.py	2009-05-13 17:19:09 UTC (rev 99895)
@@ -0,0 +1,57 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# 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.
+#
+##############################################################################
+import warnings
+
+class WarningsHook:
+    """Hook to capture warnings generated by Python.
+
+    The function warnings.showwarning() is designed to be hooked by
+    application code, allowing the application to customize the way it
+    handles warnings.
+
+    This hook captures the unformatted warning information and stores
+    it in a list.  A test can inspect this list after the test is over.
+
+    Issues:
+
+    The warnings module has lots of delicate internal state.  If
+    a warning has been reported once, it won't be reported again.  It
+    may be necessary to extend this class with a mechanism for
+    modifying the internal state so that we can be guaranteed a
+    warning will be reported.
+
+    If Python is run with a warnings filter, e.g. python -Werror,
+    then a test that is trying to inspect a particular warning will
+    fail.  Perhaps this class can be extended to install more-specific
+    filters the test to work anyway.
+    """
+
+    def __init__(self):
+        self.original = None
+        self.warnings = []
+
+    def install(self):
+        self.original = warnings.showwarning
+        warnings.showwarning = self.showwarning
+
+    def uninstall(self):
+        assert self.original is not None
+        warnings.showwarning = self.original
+        self.original = None
+
+    def showwarning(self, message, category, filename, lineno, file=None, line=None):
+        self.warnings.append((str(message), category, filename, lineno))
+
+    def clear(self):
+        self.warnings = []


Property changes on: Zope/trunk/src/Testing/ZopeTestCase/warnhook.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the Checkins mailing list