/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: Martin
  • Date: 2017-06-10 01:57:00 UTC
  • mto: This revision was merged to the branch mainline in revision 6679.
  • Revision ID: gzlist@googlemail.com-20170610015700-o3xeuyaqry2obiay
Go back to native str for urls and many other py3 changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009, 2010, 2011, 2016 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
 
 
18
import doctest
 
19
import os
 
20
import sys
 
21
 
 
22
from .. import (
 
23
    config,
 
24
    crash,
 
25
    osutils,
 
26
    plugin,
 
27
    tests,
 
28
    )
 
29
from ..sixish import (
 
30
    BytesIO,
 
31
    )
 
32
from . import features
 
33
 
 
34
 
 
35
class TestApportReporting(tests.TestCaseInTempDir):
 
36
 
 
37
    _test_needs_features = [features.apport]
 
38
 
 
39
    def test_apport_report(self):
 
40
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
 
41
        os.mkdir(crash_dir)
 
42
        self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
 
43
        self.assertEqual(crash_dir, config.crash_dir())
 
44
 
 
45
        self.overrideAttr(
 
46
            plugin,
 
47
            'plugin_warnings',
 
48
            {'example': ['Failed to load plugin foo']})
 
49
 
 
50
        stderr = BytesIO()
 
51
 
 
52
        try:
 
53
            raise AssertionError("my error")
 
54
        except AssertionError as e:
 
55
            pass
 
56
 
 
57
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
 
58
            stderr)
 
59
 
 
60
        # message explaining the crash
 
61
        self.assertContainsRe(stderr.getvalue(),
 
62
            "    apport-bug %s" % crash_filename)
 
63
 
 
64
        crash_file = open(crash_filename)
 
65
        try:
 
66
            report = crash_file.read()
 
67
        finally:
 
68
            crash_file.close()
 
69
 
 
70
        self.assertContainsRe(report,
 
71
            '(?m)^BzrVersion:') # should be in the traceback
 
72
        self.assertContainsRe(report, 'my error')
 
73
        self.assertContainsRe(report, 'AssertionError')
 
74
        # see https://bugs.launchpad.net/bzr/+bug/528114
 
75
        self.assertContainsRe(report, 'ExecutablePath')
 
76
        self.assertContainsRe(report, 'test_apport_report')
 
77
        # should also be in there
 
78
        self.assertContainsRe(report, '(?m)^CommandLine:')
 
79
        self.assertContainsRe(
 
80
            report,
 
81
            'Failed to load plugin foo')
 
82
 
 
83
 
 
84
class TestNonApportReporting(tests.TestCase):
 
85
    """Reporting of crash-type bugs without apport.
 
86
    
 
87
    This should work in all environments.
 
88
    """
 
89
 
 
90
    def setup_fake_plugins(self):
 
91
        def fake_plugins():
 
92
            fake = plugin.PlugIn('fake_plugin', plugin)
 
93
            fake.version_info = lambda: (1, 2, 3)
 
94
            return {"fake_plugin": fake}
 
95
        self.overrideAttr(plugin, 'plugins', fake_plugins)
 
96
 
 
97
    def test_report_bug_legacy(self):
 
98
        self.setup_fake_plugins()
 
99
        err_file = BytesIO()
 
100
        try:
 
101
            raise AssertionError("my error")
 
102
        except AssertionError as e:
 
103
            pass
 
104
        crash.report_bug_legacy(sys.exc_info(), err_file)
 
105
        report = err_file.getvalue()
 
106
        for needle in [
 
107
            "brz: ERROR: exceptions.AssertionError: my error",
 
108
            r"Traceback \(most recent call last\):",
 
109
            r"plugins: fake_plugin\[1\.2\.3\]",
 
110
            ]:
 
111
            self.assertContainsRe(
 
112
                    report,
 
113
                    needle)