Rev 5394: Fix bug #625686 by removing the warning filter added by selftest. in file:///home/vila/src/bzr/bugs/625686-selftest-cleanup-deprecation-warnings/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat Aug 28 16:33:23 BST 2010


At file:///home/vila/src/bzr/bugs/625686-selftest-cleanup-deprecation-warnings/

------------------------------------------------------------
revno: 5394
revision-id: v.ladeuil+lp at free.fr-20100828153322-0p194ibp8jx02e1c
parent: pqm at pqm.ubuntu.com-20100827220935-gwk3320p99ggl80n
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 625686-selftest-cleanup-deprecation-warnings
timestamp: Sat 2010-08-28 17:33:22 +0200
message:
  Fix bug #625686 by removing the warning filter added by selftest.
  
  * bzrlib/symbol_versioning.py:
  (suppress_deprecation_warnings, activate_deprecation_warnings):
  Always return a cleanup callable even if no filter is installed.
  
  * bzrlib/versionedfile.py:
  Drive-by cleanup, the module is not needed.
  
  * bzrlib/builtins.py:
  (cmd_selftest.run): Ensure we restore the right warning filters.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2010-08-27 22:09:35 +0000
+++ b/NEWS	2010-08-28 15:33:22 +0000
@@ -103,6 +103,9 @@
   directory that was a symlink in the previous commit.
   (Martin Pool, #192859)
 
+* Fix spurious paramiko warning on hardy by ensuring that ``selftest``
+  properly remove its warning filter. (Vincent Ladeuil, #625686)
+
 * ``HTTP/1.1`` test servers now set a ``Content-Length`` header to comply
   with pedantic ``HTTP/1.1`` clients. (Vincent Ladeuil, #568421)
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2010-08-20 09:39:20 +0000
+++ b/bzrlib/builtins.py	2010-08-28 15:33:22 +0000
@@ -3572,9 +3572,6 @@
             parallel=None, lsprof_tests=False):
         from bzrlib.tests import selftest
 
-        # Make deprecation warnings visible, unless -Werror is set
-        symbol_versioning.activate_deprecation_warnings(override=False)
-
         if testspecs_list is not None:
             pattern = '|'.join(testspecs_list)
         else:
@@ -3620,7 +3617,14 @@
                           "starting_with": starting_with
                           }
         selftest_kwargs.update(self.additional_selftest_args)
-        result = selftest(**selftest_kwargs)
+
+        # Make deprecation warnings visible, unless -Werror is set
+        cleanup = symbol_versioning.activate_deprecation_warnings(
+            override=False)
+        try:
+            result = selftest(**selftest_kwargs)
+        finally:
+            cleanup()
         return int(not result)
 
 

=== modified file 'bzrlib/symbol_versioning.py'
--- a/bzrlib/symbol_versioning.py	2010-06-29 16:21:13 +0000
+++ b/bzrlib/symbol_versioning.py	2010-08-28 15:33:22 +0000
@@ -29,6 +29,9 @@
            'warn',
            ]
 
+
+import warnings
+# Import the 'warn' symbol so bzrlib can call it even if we redefine it
 from warnings import warn
 
 import bzrlib
@@ -296,7 +299,6 @@
     :param error_only: Only match an 'error' filter
     :return: True if a filter is found, False otherwise
     """
-    import warnings
     for filter in warnings.filters:
         if issubclass(DeprecationWarning, filter[2]):
             # This filter will effect DeprecationWarning
@@ -305,6 +307,19 @@
     return False
 
 
+def _remove_filter_callable(filter):
+    """Build and returns a callable removing filter from the warnings.
+
+    :param filter: The filter to remove (can be None).
+
+    :return: A callable that will remove filter from warnings.filters.
+    """
+    def cleanup():
+        if filter:
+            warnings.filters.remove(filter)
+    return cleanup
+
+
 def suppress_deprecation_warnings(override=True):
     """Call this function to suppress all deprecation warnings.
 
@@ -314,18 +329,17 @@
 
     :param override: If True, always set the ignore, if False, only set the
         ignore if there isn't already a filter.
+
     :return: A callable to remove the new warnings this added.
     """
-    import warnings
     if not override and _check_for_filter(error_only=False):
         # If there is already a filter effecting suppress_deprecation_warnings,
         # then skip it.
-        return
-    warnings.filterwarnings('ignore', category=DeprecationWarning)
-    filter = warnings.filters[0]
-    def cleanup():
-        warnings.filters.remove(filter)
-    return cleanup
+        filter = None
+    else:
+        warnings.filterwarnings('ignore', category=DeprecationWarning)
+        filter = warnings.filters[0]
+    return _remove_filter_callable(filter)
 
 
 def activate_deprecation_warnings(override=True):
@@ -342,10 +356,14 @@
     :param override: If False, only add a filter if there isn't an error filter
         already. (This slightly differs from suppress_deprecation_warnings, in
         because it always overrides everything but -Werror).
+
+    :return: A callable to remove the new warnings this added.
     """
-    import warnings
     if not override and _check_for_filter(error_only=True):
         # DeprecationWarnings are already turned into errors, don't downgrade
         # them to 'default'.
-        return
-    warnings.filterwarnings('default', category=DeprecationWarning)
+        filter = None
+    else:
+        warnings.filterwarnings('default', category=DeprecationWarning)
+        filter = warnings.filters[0]
+    return _remove_filter_callable(filter)

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2010-08-16 06:46:17 +0000
+++ b/bzrlib/versionedfile.py	2010-08-28 15:33:22 +0000
@@ -46,7 +46,6 @@
 from bzrlib.transport.memory import MemoryTransport
 """)
 from bzrlib.registry import Registry
-from bzrlib.symbol_versioning import *
 from bzrlib.textmerge import TextMerge
 from bzrlib import bencode
 



More information about the bazaar-commits mailing list