~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_crash.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-20 17:19:44 UTC
  • mfrom: (4973.1.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100120171944-8gkub20gotjcye67
(spiv) Implement a per-file merge hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010, 2011 Canonical Ltd
 
1
# Copyright (C) 2009 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
20
18
from StringIO import StringIO
21
19
import sys
22
20
 
23
21
from bzrlib import (
24
 
    config,
25
22
    crash,
26
 
    osutils,
27
 
    plugin,
28
23
    tests,
29
24
    )
30
25
 
31
26
from bzrlib.tests import features
32
27
 
33
28
 
34
 
class TestApportReporting(tests.TestCaseInTempDir):
 
29
class TestApportReporting(tests.TestCase):
35
30
 
36
31
    _test_needs_features = [features.apport]
37
32
 
38
 
    def test_apport_report(self):
39
 
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
40
 
        os.mkdir(crash_dir)
41
 
        self.overrideEnv('APPORT_CRASH_DIR', crash_dir)
42
 
        self.assertEquals(crash_dir, config.crash_dir())
43
 
 
44
 
        self.overrideAttr(
45
 
            plugin,
46
 
            'plugin_warnings',
47
 
            {'example': ['Failed to load plugin foo']})
48
 
 
49
 
        stderr = StringIO()
50
 
 
 
33
    def test_apport_report_contents(self):
51
34
        try:
52
35
            raise AssertionError("my error")
53
36
        except AssertionError, e:
54
37
            pass
55
 
 
56
 
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
57
 
            stderr)
58
 
 
59
 
        # message explaining the crash
60
 
        self.assertContainsRe(stderr.getvalue(),
61
 
            "    apport-bug %s" % crash_filename)
62
 
 
63
 
        crash_file = open(crash_filename)
64
 
        try:
65
 
            report = crash_file.read()
66
 
        finally:
67
 
            crash_file.close()
68
 
 
69
 
        self.assertContainsRe(report,
70
 
            '(?m)^BzrVersion:') # should be in the traceback
 
38
        outf = StringIO()
 
39
        crash._write_apport_report_to_file(sys.exc_info(), outf)
 
40
        report = outf.getvalue()
 
41
 
 
42
        self.assertContainsRe(report, '(?m)^BzrVersion:')
 
43
        # should be in the traceback
71
44
        self.assertContainsRe(report, 'my error')
72
45
        self.assertContainsRe(report, 'AssertionError')
73
 
        # see https://bugs.launchpad.net/bzr/+bug/528114
74
 
        self.assertContainsRe(report, 'ExecutablePath')
75
 
        self.assertContainsRe(report, 'test_apport_report')
 
46
        self.assertContainsRe(report, 'test_apport_report_contents')
76
47
        # should also be in there
77
48
        self.assertContainsRe(report, '(?m)^CommandLine:')
78
 
        self.assertContainsRe(
79
 
            report,
80
 
            'Failed to load plugin foo')
81
 
 
82
 
 
83
 
class TestNonApportReporting(tests.TestCase):
84
 
    """Reporting of crash-type bugs without apport.
85
 
    
86
 
    This should work in all environments.
87
 
    """
88
 
 
89
 
    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)
95
 
 
96
 
    def test_report_bug_legacy(self):
97
 
        self.setup_fake_plugins()
98
 
        err_file = StringIO()
99
 
        try:
100
 
            raise AssertionError("my error")
101
 
        except AssertionError, e:
102
 
            pass
103
 
        crash.report_bug_legacy(sys.exc_info(), err_file)
104
 
        report = err_file.getvalue()
105
 
        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)