/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 brzlib/tests/test_crash.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

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
 
20
from StringIO import StringIO
21
21
import sys
22
22
 
23
 
import breezy
24
 
from .. import (
25
 
    bedding,
 
23
from brzlib import (
 
24
    config,
26
25
    crash,
27
26
    osutils,
28
27
    plugin,
29
28
    tests,
30
29
    )
31
 
from . import features
 
30
 
 
31
from brzlib.tests 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.assertEqual(crash_dir, bedding.crash_dir())
 
42
        self.assertEqual(crash_dir, config.crash_dir())
43
43
 
44
44
        self.overrideAttr(
45
 
            breezy.get_global_state(),
 
45
            plugin,
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 as e:
54
 
            crash_filename = crash.report_bug_to_apport(sys.exc_info(), stderr)
 
53
        except AssertionError, e:
 
54
            pass
 
55
 
 
56
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
 
57
            stderr)
55
58
 
56
59
        # message explaining the crash
57
60
        self.assertContainsRe(stderr.getvalue(),
58
 
                              "    apport-bug %s" % crash_filename)
 
61
            "    apport-bug %s" % crash_filename)
59
62
 
60
 
        with open(crash_filename) as crash_file:
 
63
        crash_file = open(crash_filename)
 
64
        try:
61
65
            report = crash_file.read()
 
66
        finally:
 
67
            crash_file.close()
62
68
 
63
69
        self.assertContainsRe(report,
64
 
                              '(?m)^BrzVersion:')  # should be in the traceback
 
70
            '(?m)^BzrVersion:') # should be in the traceback
65
71
        self.assertContainsRe(report, 'my error')
66
72
        self.assertContainsRe(report, 'AssertionError')
67
73
        # see https://bugs.launchpad.net/bzr/+bug/528114
76
82
 
77
83
class TestNonApportReporting(tests.TestCase):
78
84
    """Reporting of crash-type bugs without apport.
79
 
 
 
85
    
80
86
    This should work in all environments.
81
87
    """
82
88
 
83
89
    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)
 
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)
88
95
 
89
96
    def test_report_bug_legacy(self):
90
97
        self.setup_fake_plugins()
91
98
        err_file = StringIO()
92
99
        try:
93
100
            raise AssertionError("my error")
94
 
        except AssertionError as e:
95
 
            crash.report_bug_legacy(sys.exc_info(), err_file)
 
101
        except AssertionError, e:
 
102
            pass
 
103
        crash.report_bug_legacy(sys.exc_info(), err_file)
96
104
        report = err_file.getvalue()
97
105
        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)
 
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)