/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/blackbox/test_exceptions.py

  • Committer: Aaron Bentley
  • Date: 2006-11-17 04:06:03 UTC
  • mfrom: (2139 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2162.
  • Revision ID: aaron.bentley@utoronto.ca-20061117040603-pgebxndswvwk26tt
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Tests for display of exceptions."""
 
18
 
 
19
import os
 
20
import sys
 
21
 
 
22
from bzrlib import bzrdir, repository, trace
 
23
from bzrlib.tests import TestCaseInTempDir, TestCase, TestSkipped
 
24
from bzrlib.errors import NotBranchError
 
25
 
 
26
 
 
27
class TestExceptionReporting(TestCase):
 
28
 
 
29
    def test_report_exception(self):
 
30
        """When an error occurs, display bug report details to stderr"""
 
31
        old_use_apport = trace._use_apport
 
32
        trace._use_apport = False
 
33
        try:
 
34
            self.run_bzr_error(
 
35
                [
 
36
                    r'bzr: ERROR: exceptions\.AssertionError: always fails\n',
 
37
                    r'please send this report to',
 
38
                ],
 
39
                "assert-fail")
 
40
        finally:
 
41
            trace._use_apport = old_use_apport
 
42
 
 
43
    def test_apport_report(self):
 
44
        # If apport is present, bzr should tell the user the url to visit to 
 
45
        # file the bug, and the file to upload as an attachment containing the
 
46
        # backtrace, installed versions, plugin information etc.
 
47
        # the file contents are tested in the library tests, this test just
 
48
        # checks the ui.
 
49
        try:
 
50
            import apport_utils
 
51
        except ImportError:
 
52
            raise TestSkipped('apport not present')
 
53
        out, err = self.run_bzr_error(
 
54
            [
 
55
                r'bzr: ERROR: exceptions\.AssertionError: always fails\n',
 
56
                r'This is an unexpected error within bzr and we would appreciate a bug report.\n',
 
57
                r'bzr has written a crash report file that will assist our debugging of this\n',
 
58
                r'in the file /tmp/bzr-crash-[a-zA-Z0-9_]+\.txt\n',
 
59
                r'This is a plain text file, whose contents you can check if you have privacy\n',
 
60
                r'concerns. We gather the package data about bzr, your command line, plugins\n',
 
61
                r'And the backtrace from within bzr. If you had a password in the URL you\n',
 
62
                r'provided to bzr, you should edit that file to remove the password.\n',
 
63
                r'\*\* To file a bug for this please visit our bugtracker at the URL \n',
 
64
                r'"https://launchpad.net/products/bzr/\+filebug" and report a bug describing\n',
 
65
                r'what you were attempting and attach the bzr-crash file mentioned above.\n',
 
66
                r'Alternatively you can email bazaar-ng@lists.canonical.com with the same\n',
 
67
                r'description and attach the bzr-crash file to the email\.\n',
 
68
            ],
 
69
            "assert-fail")
 
70
        self.assertEqualDiff('', out)
 
71
 
 
72
 
 
73
    # TODO: assert-fail doesn't need to always be present; we could just
 
74
    # register (and unregister) it from tests that want to touch it.
 
75
    #
 
76
    # TODO: Some kind of test for the feature of invoking pdb
 
77
    
 
78
 
 
79
class TestDeprecationWarning(TestCaseInTempDir):
 
80
 
 
81
    def test_repository_deprecation_warning(self):
 
82
        """Old formats give a warning"""
 
83
        # the warning's normally off for testing but we reenable it
 
84
        repository._deprecation_warning_done = False
 
85
        try:
 
86
            os.mkdir('foo')
 
87
            bzrdir.BzrDirFormat5().initialize('foo')
 
88
            out, err = self.run_bzr("status", "foo")
 
89
            self.assertContainsRe(self._get_log(keep_log_file=True),
 
90
                                  "bzr upgrade")
 
91
        finally:
 
92
            repository._deprecation_warning_done = True
 
93