/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-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

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