/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Canonical Ltd
1740.5.1 by Martin Pool
When an unhandled exception occurs, write the traceback to stderr.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1740.5.1 by Martin Pool
When an unhandled exception occurs, write the traceback to stderr.
16
17
"""Tests for display of exceptions."""
18
19
import sys
20
2713.2.2 by Martin Pool
Add mention of exitcode 4 for internal errors
21
from bzrlib import (
22
    bzrdir,
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
23
    config,
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
24
    controldir,
2713.2.2 by Martin Pool
Add mention of exitcode 4 for internal errors
25
    errors,
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
26
    osutils,
2713.2.2 by Martin Pool
Add mention of exitcode 4 for internal errors
27
    repository,
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
28
    tests,
2713.2.2 by Martin Pool
Add mention of exitcode 4 for internal errors
29
    )
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
30
from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
1551.9.3 by Aaron Bentley
Revert buggy apport changes
31
5582.4.3 by Jelmer Vernooij
remove more unused imports, avoid relying on a specific set of working tree formats that support references.
32
from bzrlib.tests import TestCase
1740.5.1 by Martin Pool
When an unhandled exception occurs, write the traceback to stderr.
33
2830.2.2 by Martin Pool
Update test for report_exception to be cleaner and work with new run_bzr behavior
34
1740.5.1 by Martin Pool
When an unhandled exception occurs, write the traceback to stderr.
35
class TestExceptionReporting(TestCase):
36
2830.2.11 by Martin Pool
Integrate testing of return codes/error reporting
37
    def test_exception_exitcode(self):
2830.2.7 by Martin Pool
Return exitcode 4 on internal error
38
        # we must use a subprocess, because the normal in-memory mechanism
39
        # allows errors to propagate up through the test suite
2830.2.10 by Martin Pool
merge trunk
40
        out, err = self.run_bzr_subprocess(['assert-fail'],
2947.3.1 by Alexander Belchenko
test_exceptions.py: run_bzr_subprocess should use universal_newlines=True
41
            universal_newlines=True,
2830.2.7 by Martin Pool
Return exitcode 4 on internal error
42
            retcode=errors.EXIT_INTERNAL_ERROR)
2830.2.11 by Martin Pool
Integrate testing of return codes/error reporting
43
        self.assertEqual(4, errors.EXIT_INTERNAL_ERROR)
1551.9.3 by Aaron Bentley
Revert buggy apport changes
44
        self.assertContainsRe(err,
4584.3.32 by Martin Pool
Correct blackbox tests for new apport message
45
                r'exceptions\.AssertionError: always fails\n')
46
        self.assertContainsRe(err, r'Bazaar has encountered an internal error')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
47
5527.1.2 by Vincent Ladeuil
Report error if a non-ASCII command option is given.
48
5514.3.3 by Rory Yorke
Moved test to bb.test_exceptions, and test differently for Python 2.4.
49
class TestOptParseBugHandling(TestCase):
50
    "Test that we handle http://bugs.python.org/issue2931"
51
52
    def test_nonascii_optparse(self):
53
        """Reasonable error raised when non-ascii in option name"""
54
        if sys.version_info < (2,5):
5527.1.2 by Vincent Ladeuil
Report error if a non-ASCII command option is given.
55
            error_re = 'no such option'
5514.3.3 by Rory Yorke
Moved test to bb.test_exceptions, and test differently for Python 2.4.
56
        else:
5527.1.2 by Vincent Ladeuil
Report error if a non-ASCII command option is given.
57
            error_re = 'Only ASCII permitted in option names'
58
        out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
59
1904.2.5 by Martin Pool
Fix format warning inside test suite and add test
60
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
61
class TestObsoleteRepoFormat(RepositoryFormat2a):
62
63
    @classmethod
64
    def get_format_string(cls):
65
        return "Test Obsolete Repository Format"
66
67
    def is_deprecated(self):
68
        return True
69
70
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
71
class TestDeprecationWarning(tests.TestCaseWithTransport):
72
    """The deprecation warning is controlled via a global variable:
73
    repository._deprecation_warning_done. As such, it can be emitted only once
74
    during a bzr invocation, no matter how many repositories are involved.
75
76
    It would be better if it was a repo attribute instead but that's far more
77
    work than I want to do right now -- vila 20091215.
78
    """
79
80
    def setUp(self):
81
        super(TestDeprecationWarning, self).setUp()
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
82
        self.addCleanup(repository.format_registry.remove,
83
            TestObsoleteRepoFormat)
5675.2.7 by Jelmer Vernooij
Merge bzr.dev.
84
        repository.format_registry.register(TestObsoleteRepoFormat)
5675.2.6 by Jelmer Vernooij
Fix some tests.
85
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
86
        bzrdir.register_metadir(controldir.format_registry, "testobsolete",
87
            "bzrlib.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
88
            branch_format='bzrlib.branch.BzrBranchFormat7',
89
            tree_format='bzrlib.workingtree.WorkingTreeFormat6',
90
            deprecated=True,
91
            help='Same as 2a, but with an obsolete repo format.')
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
92
        self.disable_deprecation_warning()
93
94
    def enable_deprecation_warning(self, repo=None):
95
        """repo is not used yet since _deprecation_warning_done is a global"""
96
        repository._deprecation_warning_done = False
97
98
    def disable_deprecation_warning(self, repo=None):
99
        """repo is not used yet since _deprecation_warning_done is a global"""
100
        repository._deprecation_warning_done = True
101
102
    def make_obsolete_repo(self, path):
103
        # We don't want the deprecation raising during the repo creation
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
104
        format = controldir.format_registry.make_bzrdir("testobsolete")
105
        tree = self.make_branch_and_tree(path, format=format)
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
106
        return tree
107
108
    def check_warning(self, present):
109
        if present:
110
            check = self.assertContainsRe
111
        else:
112
            check = self.assertNotContainsRe
113
        check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
1904.2.5 by Martin Pool
Fix format warning inside test suite and add test
114
115
    def test_repository_deprecation_warning(self):
116
        """Old formats give a warning"""
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
117
        self.make_obsolete_repo('foo')
118
        self.enable_deprecation_warning()
119
        out, err = self.run_bzr('status', working_dir='foo')
120
        self.check_warning(True)
121
122
    def test_repository_deprecation_warning_suppressed_global(self):
123
        """Old formats give a warning"""
124
        conf = config.GlobalConfig()
125
        conf.set_user_option('suppress_warnings', 'format_deprecation')
126
        self.make_obsolete_repo('foo')
127
        self.enable_deprecation_warning()
128
        out, err = self.run_bzr('status', working_dir='foo')
129
        self.check_warning(False)
130
131
    def test_repository_deprecation_warning_suppressed_locations(self):
132
        """Old formats give a warning"""
133
        self.make_obsolete_repo('foo')
134
        conf = config.LocationConfig(osutils.pathjoin(self.test_dir, 'foo'))
135
        conf.set_user_option('suppress_warnings', 'format_deprecation')
136
        self.enable_deprecation_warning()
137
        out, err = self.run_bzr('status', working_dir='foo')
138
        self.check_warning(False)
139
140
    def test_repository_deprecation_warning_suppressed_branch(self):
141
        """Old formats give a warning"""
142
        tree = self.make_obsolete_repo('foo')
143
        conf = tree.branch.get_config()
144
        conf.set_user_option('suppress_warnings', 'format_deprecation')
145
        self.enable_deprecation_warning()
146
        out, err = self.run_bzr('status', working_dir='foo')
147
        self.check_warning(False)