/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): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 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
16
16
 
17
17
 
18
18
import doctest
 
19
from io import StringIO
19
20
import os
20
 
from StringIO import StringIO
21
21
import sys
22
22
 
23
 
from bzrlib import (
24
 
    config,
 
23
import breezy
 
24
from .. import (
 
25
    bedding,
25
26
    crash,
26
27
    osutils,
27
28
    plugin,
28
29
    tests,
29
30
    )
30
 
 
31
 
from bzrlib.tests import features
 
31
from . import features
32
32
 
33
33
 
34
34
class TestApportReporting(tests.TestCaseInTempDir):
39
39
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
40
40
        os.mkdir(crash_dir)
41
41
        self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
42
 
        self.assertEquals(crash_dir, config.crash_dir())
 
42
        self.assertEqual(crash_dir, bedding.crash_dir())
43
43
 
44
44
        self.overrideAttr(
45
 
            plugin,
 
45
            breezy.get_global_state(),
46
46
            'plugin_warnings',
47
47
            {'example': ['Failed to load plugin foo']})
48
48
 
50
50
 
51
51
        try:
52
52
            raise AssertionError("my error")
53
 
        except AssertionError, e:
54
 
            pass
55
 
 
56
 
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
57
 
            stderr)
 
53
        except AssertionError as e:
 
54
            crash_filename = crash.report_bug_to_apport(sys.exc_info(), stderr)
58
55
 
59
56
        # message explaining the crash
60
57
        self.assertContainsRe(stderr.getvalue(),
61
 
            "    apport-bug %s" % crash_filename)
 
58
                              "    apport-bug %s" % crash_filename)
62
59
 
63
 
        crash_file = open(crash_filename)
64
 
        try:
 
60
        with open(crash_filename) as crash_file:
65
61
            report = crash_file.read()
66
 
        finally:
67
 
            crash_file.close()
68
62
 
69
63
        self.assertContainsRe(report,
70
 
            '(?m)^BzrVersion:') # should be in the traceback
 
64
                              '(?m)^BrzVersion:')  # should be in the traceback
71
65
        self.assertContainsRe(report, 'my error')
72
66
        self.assertContainsRe(report, 'AssertionError')
73
67
        # see https://bugs.launchpad.net/bzr/+bug/528114
82
76
 
83
77
class TestNonApportReporting(tests.TestCase):
84
78
    """Reporting of crash-type bugs without apport.
85
 
    
 
79
 
86
80
    This should work in all environments.
87
81
    """
88
82
 
89
83
    def setup_fake_plugins(self):
90
 
        def fake_plugins():
91
 
            fake = plugin.PlugIn('fake_plugin', plugin)
92
 
            fake.version_info = lambda: (1, 2, 3)
93
 
            return {"fake_plugin": fake}
94
 
        self.overrideAttr(plugin, 'plugins', fake_plugins)
 
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)
95
88
 
96
89
    def test_report_bug_legacy(self):
97
90
        self.setup_fake_plugins()
98
91
        err_file = StringIO()
99
92
        try:
100
93
            raise AssertionError("my error")
101
 
        except AssertionError, e:
102
 
            pass
103
 
        crash.report_bug_legacy(sys.exc_info(), err_file)
 
94
        except AssertionError as e:
 
95
            crash.report_bug_legacy(sys.exc_info(), err_file)
104
96
        report = err_file.getvalue()
105
97
        for needle in [
106
 
            "bzr: ERROR: exceptions.AssertionError: my error",
107
 
            r"Traceback \(most recent call last\):",
108
 
            r"plugins: fake_plugin\[1\.2\.3\]",
109
 
            ]:
110
 
            self.assertContainsRe(
111
 
                    report,
112
 
                    needle)
 
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)