[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/deprecation/tests.py Changed to work regardless of previous warning settings.

Jim Fulton jim at zope.com
Tue Apr 18 19:56:34 EDT 2006


Log message for revision 67109:
  Changed to work regardless of previous warning settings.
  
  Changed to work when run multiple times.
  

Changed:
  U   Zope3/branches/jim-adapter/src/zope/deprecation/tests.py

-=-
Modified: Zope3/branches/jim-adapter/src/zope/deprecation/tests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/deprecation/tests.py	2006-04-18 23:56:31 UTC (rev 67108)
+++ Zope3/branches/jim-adapter/src/zope/deprecation/tests.py	2006-04-18 23:56:33 UTC (rev 67109)
@@ -36,18 +36,32 @@
     """Demonstrate that deprecate() also works in a local scope."""
     deprecated('demo4', 'demo4 is no more.')
 
-orig_showwarning = warnings.showwarning
+def warn(message, type_, stacklevel):
+    print "From tests.py's showwarning():"
+    
+    frame = sys._getframe(stacklevel)
+    path = frame.f_globals['__file__']
+    file = open(path)
+    lineno = frame.f_lineno
+    for i in range(lineno):
+        line = file.readline()
 
-def showwarning(message, category, filename, lineno, file=None):
-    sys.stdout.write("From tests.py's showwarning():\n")
-    sys.stdout.write(
-        warnings.formatwarning(message, category, filename, lineno))
+    print "%s:%s: %s: %s\n  %s" % (
+        path,
+        frame.f_lineno,
+        type_.__name__,
+        message,
+        line.strip(),
+        )
 
 def setUp(test):
-    warnings.showwarning = showwarning
+    test.globs['saved_warn'] = warnings.warn
+    warnings.warn = warn
 
 def tearDown(test):
-    warnings.showwarning = orig_showwarning
+    warnings.warn = test.globs['saved_warn']
+    del object.__getattribute__(sys.modules['zope.deprecation.tests'],
+                                '_DeprecationProxy__deprecated')['demo4']
 
 def test_suite():
     return unittest.TestSuite((



More information about the Zope3-Checkins mailing list