Rev 5004: Avoid infinite recursion when probing for apport. in file:///home/vila/src/bzr/bugs/516934-no-apport/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Feb 4 09:09:38 GMT 2010


At file:///home/vila/src/bzr/bugs/516934-no-apport/

------------------------------------------------------------
revno: 5004
revision-id: v.ladeuil+lp at free.fr-20100204090937-bjsmdktvv8mhlzpa
parent: pqm at pqm.ubuntu.com-20100203163347-hd3o9r24qbgofg7s
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 516934-no-apport
timestamp: Thu 2010-02-04 10:09:37 +0100
message:
  Avoid infinite recursion when probing for apport.
  
  * bzrlib/tests/test_crash.py:
  (TestApportDeprecation): Reproduce bug #516934 leading to an
  infinite recursion when apport is available.
  
  * bzrlib/tests/test_selftest.py:
  (simple_thunk_feature): Use the new signature for
  _CompatabilityThunkFeature.
  
  * bzrlib/tests/features.py:
  (ApportFeature): Use the abbreviated name instead of the full
  symbol name.
  
  * bzrlib/tests/__init__.py:
  (_CompatabilityThunkFeature.__init__): Use clearer parameter names
  to specify the feature and its replacement version. Default to the
  same module for both features.
  (_CompatabilityThunkFeature._ensure): Really thunk to the
  replacement feature. Emits two distinct messages for easier
  testing.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2010-02-03 16:33:47 +0000
+++ b/NEWS	2010-02-04 09:09:37 +0000
@@ -25,6 +25,12 @@
   automatically or by running ``apport-bug``.  No information is sent
   without specific permission from the user.  (Martin Pool, #515052)
 
+Bug Fixes
+*********
+
+* Avoid infinite recursion when probing for apport.
+  (Vincent Ladeuil, #516934)
+
 Testing
 *******
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2010-02-03 10:06:19 +0000
+++ b/bzrlib/tests/__init__.py	2010-02-04 09:09:37 +0000
@@ -4135,21 +4135,28 @@
     should really use a different feature.
     """
 
-    def __init__(self, module, name, this_name, dep_version):
+    def __init__(self, dep_version, module, name,
+                 replacement_name, replacement_module=None):
         super(_CompatabilityThunkFeature, self).__init__()
         self._module = module
+        if replacement_module is None:
+            replacement_module = module
+        self._replacement_module = replacement_module
         self._name = name
-        self._this_name = this_name
+        self._replacement_name = replacement_name
         self._dep_version = dep_version
         self._feature = None
 
     def _ensure(self):
         if self._feature is None:
-            msg = (self._dep_version % self._this_name) + (
-                   ' Use %s.%s instead.' % (self._module, self._name))
-            symbol_versioning.warn(msg, DeprecationWarning)
-            mod = __import__(self._module, {}, {}, [self._name])
-            self._feature = getattr(mod, self._name)
+            depr_msg = self._dep_version % ('%s.%s'
+                                            % (self._module, self._name))
+            use_msg = ' Use %s.%s instead.' % (self._replacement_module,
+                                               self._replacement_name)
+            symbol_versioning.warn(depr_msg + use_msg, DeprecationWarning)
+            mod = __import__(self._replacement_module, {}, {},
+                             [self._replacement_name])
+            self._feature = getattr(mod, self._replacement_name)
 
     def _probe(self):
         self._ensure()
@@ -4181,7 +4188,7 @@
         if self.available(): # Make sure the probe has been done
             return self._module
         return None
-    
+
     def feature_name(self):
         return self.module_name
 

=== modified file 'bzrlib/tests/features.py'
--- a/bzrlib/tests/features.py	2009-12-22 15:39:20 +0000
+++ b/bzrlib/tests/features.py	2010-02-04 09:09:37 +0000
@@ -20,8 +20,10 @@
 
 
 apport = tests.ModuleAvailableFeature('apport')
-ApportFeature = tests._CompatabilityThunkFeature('bzrlib.tests.features',
-    'ApportFeature', 'bzrlib.tests.features.apport', deprecated_in((2,1,0)))
+ApportFeature = tests._CompatabilityThunkFeature(
+    deprecated_in((2, 2, 0)),
+    'bzrlib.tests.features',
+    'ApportFeature', 'apport')
 paramiko = tests.ModuleAvailableFeature('paramiko')
 pycurl = tests.ModuleAvailableFeature('pycurl')
 subunit = tests.ModuleAvailableFeature('subunit')

=== modified file 'bzrlib/tests/test_crash.py'
--- a/bzrlib/tests/test_crash.py	2010-02-02 23:02:18 +0000
+++ b/bzrlib/tests/test_crash.py	2010-02-04 09:09:37 +0000
@@ -25,31 +25,36 @@
 from bzrlib import (
     config,
     crash,
+    osutils,
+    symbol_versioning,
     tests,
-    osutils,
-    )
-
-from bzrlib.tests import (
-    features,
-    TestCaseInTempDir,
-    )
-from bzrlib.tests.features import ApportFeature
-
-
-class TestApportReporting(TestCaseInTempDir):
-
-    _test_needs_features = [features.apport]
-
-    def setUp(self):
-        TestCaseInTempDir.setUp(self)
-        self.requireFeature(ApportFeature)
+    )
+
+from bzrlib.tests import features
+
+
+class TestApportDeprecation(tests.TestCaseInTempDir):
+
+    _test_needs_features = [features.apport]
+
+    def test_deprecation(self):
+        res = self.callDeprecated(
+            ['bzrlib.tests.features.ApportFeature was deprecated'
+             ' in version 2.2.0. Use bzrlib.tests.features.apport instead.'],
+            features.ApportFeature.available)
+        self.assertEqual(res, features.ApportFeature.available())
+
+
+class TestApportReporting(tests.TestCaseInTempDir):
+
+    _test_needs_features = [features.apport]
 
     def test_apport_report(self):
         crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
         os.mkdir(crash_dir)
         os.environ['APPORT_CRASH_DIR'] = crash_dir
         self.assertEquals(crash_dir, config.crash_dir())
-    
+
         stderr = StringIO()
 
         try:

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2010-01-25 17:48:22 +0000
+++ b/bzrlib/tests/test_selftest.py	2010-02-04 09:09:37 +0000
@@ -2400,9 +2400,11 @@
 
 
 simple_thunk_feature = tests._CompatabilityThunkFeature(
-    'bzrlib.tests', 'UnicodeFilename',
-    'bzrlib.tests.test_selftest.simple_thunk_feature',
-    deprecated_in((2,1,0)))
+    deprecated_in((2, 1, 0)),
+    'bzrlib.tests.test_selftest',
+    'simple_thunk_feature','UnicodeFilename',
+    replacement_module='bzrlib.tests'
+    )
 
 class Test_CompatibilityFeature(tests.TestCase):
 
@@ -2413,7 +2415,7 @@
             simple_thunk_feature.available)
         self.assertEqual(tests.UnicodeFilename.available(), res)
 
-        
+
 class TestModuleAvailableFeature(tests.TestCase):
 
     def test_available_module(self):



More information about the bazaar-commits mailing list