~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_crash.py

  • Committer: Martin Pool
  • Date: 2011-03-29 05:20:04 UTC
  • mto: (5609.29.1 2.3)
  • mto: This revision was merged to the branch mainline in revision 5755.
  • Revision ID: mbp@canonical.com-20110329052004-4hhjfwkda0ucbk2y
Show concise list of plugins in non-apport crash; add test for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
 
18
import doctest
 
19
import os
18
20
from StringIO import StringIO
19
21
import sys
20
22
 
21
23
 
22
 
import os
23
 
 
24
 
 
25
24
from bzrlib import (
26
25
    config,
27
26
    crash,
28
27
    osutils,
 
28
    plugin,
29
29
    tests,
30
30
    )
31
31
 
71
71
        self.assertContainsRe(report, 'test_apport_report')
72
72
        # should also be in there
73
73
        self.assertContainsRe(report, '(?m)^CommandLine:')
 
74
 
 
75
 
 
76
class TestNonApportReporting(tests.TestCase):
 
77
    """Reporting of crash-type bugs without apport.
 
78
    
 
79
    This should work in all environments.
 
80
    """
 
81
 
 
82
    def setup_fake_plugins(self):
 
83
        def fake_plugins():
 
84
            fake = plugin.PlugIn('fake_plugin', plugin)
 
85
            fake.version_info = lambda: (1, 2, 3)
 
86
            return {"fake_plugin": fake}
 
87
        self.overrideAttr(plugin, 'plugins', fake_plugins)
 
88
 
 
89
    def test_report_bug_legacy(self):
 
90
        self.setup_fake_plugins()
 
91
        err_file = StringIO()
 
92
        try:
 
93
            raise AssertionError("my error")
 
94
        except AssertionError, e:
 
95
            pass
 
96
        crash.report_bug_legacy(sys.exc_info(), err_file)
 
97
        self.assertDoctestExampleMatches("""\
 
98
bzr: ERROR: exceptions.AssertionError: my error
 
99
<BLANKLINE>
 
100
Traceback (most recent call last):
 
101
  ...
 
102
AssertionError: my error
 
103
<BLANKLINE>
 
104
bzr ... on python ...
 
105
arguments: ...
 
106
plugins: fake_plugin[1.2.3]
 
107
encoding: ...
 
108
<BLANKLINE>
 
109
*** Bazaar has encountered an internal error.  This probably indicates a
 
110
    bug in Bazaar.  You can help us fix it by filing a bug report at
 
111
        https://bugs.launchpad.net/bzr/+filebug
 
112
    including this traceback and a description of the problem.
 
113
""", 
 
114
    err_file.getvalue(),
 
115
    )