/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_crash.py

  • Committer: Martin Pool
  • Date: 2011-04-01 03:07:34 UTC
  • mfrom: (5609.29.3 2.3)
  • mto: (5609.29.4 2.3)
  • mto: This revision was merged to the branch mainline in revision 5755.
  • Revision ID: mbp@canonical.com-20110401030734-wip8a66uf8aphgud
merge up to bzr 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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,
27
27
    crash,
28
28
    osutils,
29
 
    symbol_versioning,
 
29
    plugin,
30
30
    tests,
31
31
    )
32
32
 
40
40
    def test_apport_report(self):
41
41
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
42
42
        os.mkdir(crash_dir)
43
 
        os.environ['APPORT_CRASH_DIR'] = crash_dir
 
43
        self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
44
44
        self.assertEquals(crash_dir, config.crash_dir())
45
45
 
46
46
        stderr = StringIO()
72
72
        self.assertContainsRe(report, 'test_apport_report')
73
73
        # should also be in there
74
74
        self.assertContainsRe(report, '(?m)^CommandLine:')
 
75
 
 
76
 
 
77
class TestNonApportReporting(tests.TestCase):
 
78
    """Reporting of crash-type bugs without apport.
 
79
    
 
80
    This should work in all environments.
 
81
    """
 
82
 
 
83
    def setup_fake_plugins(self):
 
84
        def fake_plugins():
 
85
            fake = plugin.PlugIn('fake_plugin', plugin)
 
86
            fake.version_info = lambda: (1, 2, 3)
 
87
            return {"fake_plugin": fake}
 
88
        self.overrideAttr(plugin, 'plugins', fake_plugins)
 
89
 
 
90
    def test_report_bug_legacy(self):
 
91
        self.setup_fake_plugins()
 
92
        err_file = StringIO()
 
93
        try:
 
94
            raise AssertionError("my error")
 
95
        except AssertionError, e:
 
96
            pass
 
97
        crash.report_bug_legacy(sys.exc_info(), err_file)
 
98
        self.assertThat(
 
99
            err_file.getvalue(),
 
100
            DocTestMatches("""\
 
101
bzr: ERROR: exceptions.AssertionError: my error
 
102
 
 
103
Traceback (most recent call last):
 
104
  ...
 
105
AssertionError: my error
 
106
 
 
107
bzr ... on python ...
 
108
arguments: ...
 
109
plugins: fake_plugin[1.2.3]
 
110
encoding: ...
 
111
 
 
112
*** Bazaar has encountered an internal error.  This probably indicates a
 
113
    bug in Bazaar.  You can help us fix it by filing a bug report at
 
114
        https://bugs.launchpad.net/bzr/+filebug
 
115
    including this traceback and a description of the problem.
 
116
""", flags=doctest.ELLIPSIS|doctest.REPORT_UDIFF))