~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_crash.py

  • Committer: Andrew Bennetts
  • Date: 2011-04-08 03:31:54 UTC
  • mfrom: (5766 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5767.
  • Revision ID: andrew.bennetts@canonical.com-20110408033154-la08nghd4391sw5m
Merge latest lp:bzr, move our new release notes entries to the current release.

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
 
 
22
 
import os
23
 
 
 
23
from testtools.matchers import DocTestMatches
24
24
 
25
25
from bzrlib import (
26
26
    config,
80
80
        self.assertContainsRe(
81
81
            report,
82
82
            'Failed to load plugin foo')
 
83
 
 
84
 
 
85
class TestNonApportReporting(tests.TestCase):
 
86
    """Reporting of crash-type bugs without apport.
 
87
    
 
88
    This should work in all environments.
 
89
    """
 
90
 
 
91
    def setup_fake_plugins(self):
 
92
        def fake_plugins():
 
93
            fake = plugin.PlugIn('fake_plugin', plugin)
 
94
            fake.version_info = lambda: (1, 2, 3)
 
95
            return {"fake_plugin": fake}
 
96
        self.overrideAttr(plugin, 'plugins', fake_plugins)
 
97
 
 
98
    def test_report_bug_legacy(self):
 
99
        self.setup_fake_plugins()
 
100
        err_file = StringIO()
 
101
        try:
 
102
            raise AssertionError("my error")
 
103
        except AssertionError, e:
 
104
            pass
 
105
        crash.report_bug_legacy(sys.exc_info(), err_file)
 
106
        self.assertThat(
 
107
            err_file.getvalue(),
 
108
            DocTestMatches("""\
 
109
bzr: ERROR: exceptions.AssertionError: my error
 
110
 
 
111
Traceback (most recent call last):
 
112
  ...
 
113
AssertionError: my error
 
114
 
 
115
bzr ... on python ...
 
116
arguments: ...
 
117
plugins: fake_plugin[1.2.3]
 
118
encoding: ...
 
119
 
 
120
*** Bazaar has encountered an internal error.  This probably indicates a
 
121
    bug in Bazaar.  You can help us fix it by filing a bug report at
 
122
        https://bugs.launchpad.net/bzr/+filebug
 
123
    including this traceback and a description of the problem.
 
124
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))