/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2006, 2007, 2009-2012, 2016 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
5785.1.1 by Martin
Add blackbox test for reporting of argv encoding failures
19
import os
5939.4.2 by Jelmer Vernooij
Use re.MULTILINE rather than removing the anchor.
20
import re
1740.5.1 by Martin Pool
When an unhandled exception occurs, write the traceback to stderr.
21
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
22
from breezy import (
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
23
    bzr,
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
24
    config,
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
25
    controldir,
2713.2.2 by Martin Pool
Add mention of exitcode 4 for internal errors
26
    errors,
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
27
    osutils,
2713.2.2 by Martin Pool
Add mention of exitcode 4 for internal errors
28
    repository,
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
29
    tests,
2713.2.2 by Martin Pool
Add mention of exitcode 4 for internal errors
30
    )
7078.15.1 by Jelmer Vernooij
Fix some more tests.
31
from breezy.sixish import PY3
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
32
from breezy.bzr.groupcompress_repo import RepositoryFormat2a
1551.9.3 by Aaron Bentley
Revert buggy apport changes
33
5984.1.1 by Vincent Ladeuil
Some cleanup and a first try at fixing bug #798698.
34
35
class TestExceptionReporting(tests.TestCaseInTempDir):
1740.5.1 by Martin Pool
When an unhandled exception occurs, write the traceback to stderr.
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'],
7143.15.2 by Jelmer Vernooij
Run autopep8.
41
                                           universal_newlines=True,
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)
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
44
        self.assertContainsRe(err, br'\nAssertionError: always fails\n')
7143.15.2 by Jelmer Vernooij
Run autopep8.
45
        self.assertContainsRe(
46
            err, br'Bazaar has encountered an internal error')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
47
5785.1.1 by Martin
Add blackbox test for reporting of argv encoding failures
48
    def test_undecodable_argv(self):
49
        """A user error must be reported if argv is not in the locale encoding
50
51
        A subprocess with an environment ascii-only setting is used so the test
52
        can run without worrying about the locale the test suite is using.
53
        """
54
        if os.name != "posix":
5785.1.3 by Martin
Tweak argv encoding error message
55
            raise tests.TestNotApplicable("Needs system beholden to C locales")
7078.4.1 by Jelmer Vernooij
Skip undecodable_argv test.
56
        if PY3:
7143.15.2 by Jelmer Vernooij
Run autopep8.
57
            raise tests.TestNotApplicable(
58
                "Unable to pass argv to subprocess as bytes")
7078.15.1 by Jelmer Vernooij
Fix some more tests.
59
        out, err = self.run_bzr_subprocess([b"\xa0"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
60
                                           env_changes={
61
                                               "LANG": "C", "LC_ALL": "C"},
62
                                           universal_newlines=True,
63
                                           retcode=errors.EXIT_ERROR)
7045.3.1 by Jelmer Vernooij
Fix another ~500 tests.
64
        self.assertContainsRe(err, br"^brz: ERROR: .*'\\xa0'.* unsupported",
7143.15.2 by Jelmer Vernooij
Run autopep8.
65
                              flags=re.MULTILINE)
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
66
        self.assertEqual(out, b"")
5785.1.1 by Martin
Add blackbox test for reporting of argv encoding failures
67
6352.3.1 by Martin Packman
Add test for working with non-ascii filenames under the C locale
68
    def test_utf8_default_fs_enc(self):
6622.1.29 by Jelmer Vernooij
Fix some more tests.
69
        """In the C locale brz treats a posix filesystem as UTF-8 encoded"""
6352.3.1 by Martin Packman
Add test for working with non-ascii filenames under the C locale
70
        if os.name != "posix":
71
            raise tests.TestNotApplicable("Needs system beholden to C locales")
72
        out, err = self.run_bzr_subprocess(["init", "file:%C2%A7"],
7143.15.2 by Jelmer Vernooij
Run autopep8.
73
                                           env_changes={"LANG": "C", "LC_ALL": "C"})
7027.10.1 by Jelmer Vernooij
Various blackbox test fixes.
74
        self.assertContainsRe(out, b"^Created a standalone tree .*$")
6352.3.1 by Martin Packman
Add test for working with non-ascii filenames under the C locale
75
5527.1.2 by Vincent Ladeuil
Report error if a non-ASCII command option is given.
76
5984.1.2 by Vincent Ladeuil
Really fix it.
77
class TestOptParseBugHandling(tests.TestCase):
5514.3.3 by Rory Yorke
Moved test to bb.test_exceptions, and test differently for Python 2.4.
78
    "Test that we handle http://bugs.python.org/issue2931"
79
80
    def test_nonascii_optparse(self):
7078.15.1 by Jelmer Vernooij
Fix some more tests.
81
        """Reasonable error raised when non-ascii in option name on Python 2"""
82
        if PY3:
83
            error_re = u'no such option: -\xe4'
84
        else:
85
            error_re = 'Only ASCII permitted in option names'
6809.1.1 by Martin
Apply 2to3 ws_comma fixer
86
        out = self.run_bzr_error([error_re], ['st', u'-\xe4'])
5527.1.2 by Vincent Ladeuil
Report error if a non-ASCII command option is given.
87
1904.2.5 by Martin Pool
Fix format warning inside test suite and add test
88
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
89
class TestObsoleteRepoFormat(RepositoryFormat2a):
90
91
    @classmethod
92
    def get_format_string(cls):
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
93
        return b"Test Obsolete Repository Format"
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
94
95
    def is_deprecated(self):
96
        return True
97
98
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
99
class TestDeprecationWarning(tests.TestCaseWithTransport):
100
    """The deprecation warning is controlled via a global variable:
101
    repository._deprecation_warning_done. As such, it can be emitted only once
6622.1.29 by Jelmer Vernooij
Fix some more tests.
102
    during a brz invocation, no matter how many repositories are involved.
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
103
104
    It would be better if it was a repo attribute instead but that's far more
105
    work than I want to do right now -- vila 20091215.
106
    """
107
108
    def setUp(self):
109
        super(TestDeprecationWarning, self).setUp()
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
110
        self.addCleanup(repository.format_registry.remove,
7143.15.2 by Jelmer Vernooij
Run autopep8.
111
                        TestObsoleteRepoFormat)
5675.2.7 by Jelmer Vernooij
Merge bzr.dev.
112
        repository.format_registry.register(TestObsoleteRepoFormat)
5675.2.6 by Jelmer Vernooij
Fix some tests.
113
        self.addCleanup(controldir.format_registry.remove, "testobsolete")
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
114
        bzr.register_metadir(controldir.format_registry, "testobsolete",
7143.15.2 by Jelmer Vernooij
Run autopep8.
115
                             "breezy.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
116
                             branch_format='breezy.bzr.branch.BzrBranchFormat7',
117
                             tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
118
                             deprecated=True,
119
                             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
120
        self.disable_deprecation_warning()
121
122
    def enable_deprecation_warning(self, repo=None):
123
        """repo is not used yet since _deprecation_warning_done is a global"""
124
        repository._deprecation_warning_done = False
125
126
    def disable_deprecation_warning(self, repo=None):
127
        """repo is not used yet since _deprecation_warning_done is a global"""
128
        repository._deprecation_warning_done = True
129
130
    def make_obsolete_repo(self, path):
131
        # We don't want the deprecation raising during the repo creation
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
132
        format = controldir.format_registry.make_controldir("testobsolete")
5675.2.1 by Jelmer Vernooij
Add RepositoryFormat.is_deprecated(). This removes the need for
133
        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
134
        return tree
135
136
    def check_warning(self, present):
137
        if present:
138
            check = self.assertContainsRe
139
        else:
140
            check = self.assertNotContainsRe
6622.1.29 by Jelmer Vernooij
Fix some more tests.
141
        check(self.get_log(), 'WARNING.*brz upgrade')
1904.2.5 by Martin Pool
Fix format warning inside test suite and add test
142
143
    def test_repository_deprecation_warning(self):
144
        """Old formats give a warning"""
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
145
        self.make_obsolete_repo('foo')
146
        self.enable_deprecation_warning()
147
        out, err = self.run_bzr('status', working_dir='foo')
148
        self.check_warning(True)
149
150
    def test_repository_deprecation_warning_suppressed_global(self):
151
        """Old formats give a warning"""
6449.1.1 by Jelmer Vernooij
Convert 'suppress_warnings' option to config stacks.
152
        conf = config.GlobalStack()
153
        conf.set('suppress_warnings', 'format_deprecation')
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
154
        self.make_obsolete_repo('foo')
155
        self.enable_deprecation_warning()
156
        out, err = self.run_bzr('status', working_dir='foo')
157
        self.check_warning(False)
158
159
    def test_repository_deprecation_warning_suppressed_locations(self):
160
        """Old formats give a warning"""
161
        self.make_obsolete_repo('foo')
6449.1.1 by Jelmer Vernooij
Convert 'suppress_warnings' option to config stacks.
162
        conf = config.LocationStack(osutils.pathjoin(self.test_dir, 'foo'))
163
        conf.set('suppress_warnings', 'format_deprecation')
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
164
        self.enable_deprecation_warning()
165
        out, err = self.run_bzr('status', working_dir='foo')
166
        self.check_warning(False)
167
168
    def test_repository_deprecation_warning_suppressed_branch(self):
169
        """Old formats give a warning"""
170
        tree = self.make_obsolete_repo('foo')
6449.1.1 by Jelmer Vernooij
Convert 'suppress_warnings' option to config stacks.
171
        conf = tree.branch.get_config_stack()
172
        conf.set('suppress_warnings', 'format_deprecation')
4840.2.7 by Vincent Ladeuil
Move the _warn_if_deprecated call from repo.__init__ to
173
        self.enable_deprecation_warning()
174
        out, err = self.run_bzr('status', working_dir='foo')
175
        self.check_warning(False)