Rev 5633: (mbp) show plugins, but only briefly, in file:///home/pqm/archives/thelove/bzr/2.3/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Mar 31 09:24:35 UTC 2011


At file:///home/pqm/archives/thelove/bzr/2.3/

------------------------------------------------------------
revno: 5633 [merge]
revision-id: pqm at pqm.ubuntu.com-20110331092432-lgbslvzkl06y12xk
parent: pqm at pqm.ubuntu.com-20110323120011-3b3tzjsj0er2rp4y
parent: mbp at canonical.com-20110331084723-vc2pl0tujlsin0sx
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.3
timestamp: Thu 2011-03-31 09:24:32 +0000
message:
  (mbp) show plugins, but only briefly,
   in the non-apport crash report (Martin Pool)
modified:
  bzrlib/crash.py                crash.py-20090812083334-d6volool4lktdjcx-1
  bzrlib/plugin.py               plugin.py-20050622060424-829b654519533d69
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
  bzrlib/tests/test_crash.py     test_crash.py-20090820042958-jglgza3wrn03ha9e-2
  bzrlib/tests/test_selftest.py  test_selftest.py-20051202044319-c110a115d8c0456a
  doc/developers/testing.txt     testing.txt-20080812140359-i70zzh6v2z7grqex-1
  doc/en/release-notes/bzr-2.3.txt NEWS-20050323055033-4e00b5db738777ff
=== modified file 'bzrlib/crash.py'
--- a/bzrlib/crash.py	2010-09-28 18:51:47 +0000
+++ b/bzrlib/crash.py	2011-03-29 05:20:04 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2009, 2010 Canonical Ltd
+# Copyright (C) 2009-2011 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -84,19 +84,27 @@
     """Report a bug by just printing a message to the user."""
     trace.print_exception(exc_info, err_file)
     err_file.write('\n')
-    err_file.write('bzr %s on python %s (%s)\n' % \
-                       (bzrlib.__version__,
-                        bzrlib._format_version_tuple(sys.version_info),
-                        platform.platform(aliased=1)))
-    err_file.write('arguments: %r\n' % sys.argv)
-    err_file.write(
+    import textwrap
+    def print_wrapped(l):
+        err_file.write(textwrap.fill(l,
+            width=78, subsequent_indent='    ') + '\n')
+    print_wrapped('bzr %s on python %s (%s)\n' % \
+        (bzrlib.__version__,
+        bzrlib._format_version_tuple(sys.version_info),
+        platform.platform(aliased=1)))
+    print_wrapped('arguments: %r\n' % sys.argv)
+    print_wrapped(textwrap.fill(
+        'plugins: ' + plugin.format_concise_plugin_list(),
+        width=78,
+        subsequent_indent='    ',
+        ) + '\n')
+    print_wrapped(
         'encoding: %r, fsenc: %r, lang: %r\n' % (
             osutils.get_user_encoding(), sys.getfilesystemencoding(),
             os.environ.get('LANG')))
-    err_file.write("plugins:\n")
-    err_file.write(_format_plugin_list())
+    # We used to show all the plugins here, but it's too verbose.
     err_file.write(
-        "\n\n"
+        "\n"
         "*** Bazaar has encountered an internal error.  This probably indicates a\n"
         "    bug in Bazaar.  You can help us fix it by filing a bug report at\n"
         "        https://bugs.launchpad.net/bzr/+filebug\n"

=== modified file 'bzrlib/plugin.py'
--- a/bzrlib/plugin.py	2010-06-11 08:02:42 +0000
+++ b/bzrlib/plugin.py	2011-03-29 05:20:04 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2005-2010 Canonical Ltd
+# Copyright (C) 2005-2011 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -400,6 +400,17 @@
     return result
 
 
+def format_concise_plugin_list():
+    """Return a string holding a concise list of plugins and their version.
+    """
+    items = []
+    for name, a_plugin in sorted(plugins().items()):
+        items.append("%s[%s]" %
+            (name, a_plugin.__version__))
+    return ', '.join(items)
+
+
+
 class PluginsHelpIndex(object):
     """A help index that returns help topics for plugins."""
 

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2011-01-26 19:35:07 +0000
+++ b/bzrlib/tests/__init__.py	2011-03-29 05:19:48 +0000
@@ -1450,6 +1450,26 @@
         else:
             self.assertEqual(expected_docstring, obj.__doc__)
 
+    def assertDoctestExampleMatches(self, expected, actual, optionflags=None):
+        """Check for a doctest-style string match.
+
+        :param optionflags: or'd together integers from doctest, typically
+        including ELLIPSIS.  If not passed, reasonable defaults are passed.
+        """
+        checker = doctest.OutputChecker()
+        if optionflags is None:
+            # XXX: More here by default?
+            optionflags = doctest.ELLIPSIS | doctest.REPORT_UDIFF
+        if not checker.check_output(expected, actual, optionflags):
+            # The Doctest api insists on an internal object here but doesn't
+            # really need it; just pretend.
+            class FakeExample:
+                pass
+            example = FakeExample()
+            example.want = expected
+            self.fail("doctest-type check failed: "
+                + checker.output_difference(example, actual, optionflags))
+
     def failUnlessExists(self, path):
         """Fail unless path or paths, which may be abs or relative, exist."""
         if not isinstance(path, basestring):

=== modified file 'bzrlib/tests/test_crash.py'
--- a/bzrlib/tests/test_crash.py	2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_crash.py	2011-03-31 05:45:39 +0000
@@ -15,17 +15,17 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 
+import doctest
+import os
 from StringIO import StringIO
 import sys
 
 
-import os
-
-
 from bzrlib import (
     config,
     crash,
     osutils,
+    plugin,
     tests,
     )
 
@@ -71,3 +71,45 @@
         self.assertContainsRe(report, 'test_apport_report')
         # should also be in there
         self.assertContainsRe(report, '(?m)^CommandLine:')
+
+
+class TestNonApportReporting(tests.TestCase):
+    """Reporting of crash-type bugs without apport.
+    
+    This should work in all environments.
+    """
+
+    def setup_fake_plugins(self):
+        def fake_plugins():
+            fake = plugin.PlugIn('fake_plugin', plugin)
+            fake.version_info = lambda: (1, 2, 3)
+            return {"fake_plugin": fake}
+        self.overrideAttr(plugin, 'plugins', fake_plugins)
+
+    def test_report_bug_legacy(self):
+        self.setup_fake_plugins()
+        err_file = StringIO()
+        try:
+            raise AssertionError("my error")
+        except AssertionError, e:
+            pass
+        crash.report_bug_legacy(sys.exc_info(), err_file)
+        self.assertDoctestExampleMatches("""\
+bzr: ERROR: exceptions.AssertionError: my error
+
+Traceback (most recent call last):
+  ...
+AssertionError: my error
+
+bzr ... on python ...
+arguments: ...
+plugins: fake_plugin[1.2.3]
+encoding: ...
+
+*** Bazaar has encountered an internal error.  This probably indicates a
+    bug in Bazaar.  You can help us fix it by filing a bug report at
+        https://bugs.launchpad.net/bzr/+filebug
+    including this traceback and a description of the problem.
+""", 
+    err_file.getvalue(),
+    )

=== modified file 'bzrlib/tests/test_selftest.py'
--- a/bzrlib/tests/test_selftest.py	2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_selftest.py	2011-03-29 04:43:16 +0000
@@ -1327,6 +1327,14 @@
         self.assertEqual('Incorrect length: wanted 2, got 3 for [1, 2, 3]',
             exception.args[0])
 
+    def test_assertDoctestExampleMatches(self):
+        self.assertDoctestExampleMatches("expected", "expected")
+        self.assertDoctestExampleMatches("hello ... world",
+            "hello round blue world")
+        self.assertRaises(AssertionError,
+            self.assertDoctestExampleMatches,
+            "blue\n", "green\n")
+
     def test_base_setUp_not_called_causes_failure(self):
         class TestCaseWithBrokenSetUp(tests.TestCase):
             def setUp(self):

=== modified file 'doc/developers/testing.txt'
--- a/doc/developers/testing.txt	2011-01-03 13:13:50 +0000
+++ b/doc/developers/testing.txt	2011-03-29 04:43:16 +0000
@@ -339,6 +339,11 @@
 
   __ http://docs.python.org/lib/module-doctest.html
 
+There is an `assertDoctestExampleMatches` method in
+`bzrlib.tests.TestCase` that allows you to match against doctest-style
+string templates (including ``...`` to skip sections) from regular Python
+tests.
+
 
 Shell-like tests
 ----------------

=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- a/doc/en/release-notes/bzr-2.3.txt	2011-03-23 11:07:49 +0000
+++ b/doc/en/release-notes/bzr-2.3.txt	2011-03-31 08:47:23 +0000
@@ -39,6 +39,10 @@
 .. Fixes for situations where bzr would previously crash or give incorrect
    or undesirable results.
 
+* When reporting a crash without apport, don't print the full list of
+   plugins because it's often too long.
+   (Martin Pool, #716389)
+
 * ``bzr push`` into a repository (that doesn't have a branch), will no
   longer copy all revisions in the repository. Only the ones in the
   ancestry of the source branch, like it does in all other cases.
@@ -79,6 +83,10 @@
   (<http://psf.upfronthosting.co.za/roundup/tracker/issue8194> should be fixed
   in python > 2.7.1).  (Vincent Ladeuil, #654733)
 
+* New assertion method `assertDoctestExampleMatches` allows easily reusing
+  doctest string template matches against arbitrary strings.
+  (Martin Pool)
+
 
 bzr 2.3.1
 #########




More information about the bazaar-commits mailing list