/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 breezy/tests/test_crash.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

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, 2016 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
 
from StringIO import StringIO
 
18
import doctest
 
19
from io import StringIO
 
20
import os
19
21
import sys
20
22
 
21
 
 
22
 
import os
23
 
 
24
 
 
25
 
from bzrlib import (
26
 
    config,
 
23
import breezy
 
24
from .. import (
 
25
    bedding,
27
26
    crash,
28
27
    osutils,
29
 
    symbol_versioning,
 
28
    plugin,
30
29
    tests,
31
30
    )
32
 
 
33
 
from bzrlib.tests import features
 
31
from . import features
34
32
 
35
33
 
36
34
class TestApportReporting(tests.TestCaseInTempDir):
40
38
    def test_apport_report(self):
41
39
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
42
40
        os.mkdir(crash_dir)
43
 
        os.environ['APPORT_CRASH_DIR'] = crash_dir
44
 
        self.assertEquals(crash_dir, config.crash_dir())
 
41
        self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
 
42
        self.assertEqual(crash_dir, bedding.crash_dir())
 
43
 
 
44
        self.overrideAttr(
 
45
            breezy.get_global_state(),
 
46
            'plugin_warnings',
 
47
            {'example': ['Failed to load plugin foo']})
45
48
 
46
49
        stderr = StringIO()
47
50
 
48
51
        try:
49
52
            raise AssertionError("my error")
50
 
        except AssertionError, e:
51
 
            pass
52
 
 
53
 
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
54
 
            stderr)
 
53
        except AssertionError as e:
 
54
            crash_filename = crash.report_bug_to_apport(sys.exc_info(), stderr)
55
55
 
56
56
        # message explaining the crash
57
57
        self.assertContainsRe(stderr.getvalue(),
58
 
            "    apport-bug %s" % crash_filename)
 
58
                              "    apport-bug %s" % crash_filename)
59
59
 
60
 
        crash_file = open(crash_filename)
61
 
        try:
 
60
        with open(crash_filename) as crash_file:
62
61
            report = crash_file.read()
63
 
        finally:
64
 
            crash_file.close()
65
62
 
66
63
        self.assertContainsRe(report,
67
 
            '(?m)^BzrVersion:') # should be in the traceback
 
64
                              '(?m)^BrzVersion:')  # should be in the traceback
68
65
        self.assertContainsRe(report, 'my error')
69
66
        self.assertContainsRe(report, 'AssertionError')
70
67
        # see https://bugs.launchpad.net/bzr/+bug/528114
72
69
        self.assertContainsRe(report, 'test_apport_report')
73
70
        # should also be in there
74
71
        self.assertContainsRe(report, '(?m)^CommandLine:')
 
72
        self.assertContainsRe(
 
73
            report,
 
74
            'Failed to load plugin foo')
 
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
        fake = plugin.PlugIn('fake_plugin', plugin)
 
85
        fake.version_info = lambda: (1, 2, 3)
 
86
        fake_plugins = {"fake_plugin": fake}
 
87
        self.overrideAttr(breezy.get_global_state(), '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 as e:
 
95
            crash.report_bug_legacy(sys.exc_info(), err_file)
 
96
        report = err_file.getvalue()
 
97
        for needle in [
 
98
                "brz: ERROR: AssertionError: my error",
 
99
                r"Traceback \(most recent call last\):",
 
100
                r"plugins: fake_plugin\[1\.2\.3\]",
 
101
                ]:
 
102
            self.assertContainsRe(report, needle)