Rev 5399: (vila) Cleanup warnings.filters after running selftest (Vincent in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Aug 31 11:16:36 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5399 [merge]
revision-id: pqm at pqm.ubuntu.com-20100831101633-ta0o6c60gy2pc0as
parent: pqm at pqm.ubuntu.com-20100830224920-w9zw1vhsd5oiyljv
parent: v.ladeuil+lp at free.fr-20100831085728-ek5579227gt3llk5
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2010-08-31 11:16:33 +0100
message:
  (vila) Cleanup warnings.filters after running selftest (Vincent
  	Ladeuil)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/symbol_versioning.py    symbol_versioning.py-20060105104851-9ecf8af605d15a80
  bzrlib/versionedfile.py        versionedfile.py-20060222045106-5039c71ee3b65490
=== modified file 'NEWS'
--- a/NEWS	2010-08-30 10:14:21 +0000
+++ b/NEWS	2010-08-31 08:57:28 +0000
@@ -118,6 +118,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-30 07:47:38 +0000
+++ b/bzrlib/builtins.py	2010-08-31 08:57:28 +0000
@@ -3572,9 +3572,6 @@
             parallel=None, lsprof_tests=False):
         from bzrlib import tests
 
-        # 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 = tests.selftest(**selftest_kwargs)
+
+        # Make deprecation warnings visible, unless -Werror is set
+        cleanup = symbol_versioning.activate_deprecation_warnings(
+            override=False)
+        try:
+            result = tests.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:34:24 +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:34:24 +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