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

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

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