/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: Jelmer Vernooij
  • Date: 2017-06-10 21:59:15 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610215915-zcpu0in3r1irx3ml
Move serializer to bzr.

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
import os
19
20
import sys
20
21
 
21
 
 
22
 
import os
23
 
 
24
 
 
25
 
from bzrlib import (
 
22
from .. import (
26
23
    config,
27
24
    crash,
28
25
    osutils,
29
 
    symbol_versioning,
 
26
    plugin,
30
27
    tests,
31
28
    )
32
 
 
33
 
from bzrlib.tests import features
 
29
from ..sixish import (
 
30
    BytesIO,
 
31
    )
 
32
from . import features
34
33
 
35
34
 
36
35
class TestApportReporting(tests.TestCaseInTempDir):
40
39
    def test_apport_report(self):
41
40
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
42
41
        os.mkdir(crash_dir)
43
 
        os.environ['APPORT_CRASH_DIR'] = crash_dir
44
 
        self.assertEquals(crash_dir, config.crash_dir())
45
 
 
46
 
        stderr = StringIO()
 
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()
47
51
 
48
52
        try:
49
53
            raise AssertionError("my error")
50
 
        except AssertionError, e:
 
54
        except AssertionError as e:
51
55
            pass
52
56
 
53
57
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
72
76
        self.assertContainsRe(report, 'test_apport_report')
73
77
        # should also be in there
74
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)