17
17
"""Tests for display of exceptions."""
19
from cStringIO import StringIO
33
from bzrlib.tests import TestCaseInTempDir, TestCase
34
from bzrlib.errors import NotBranchError
37
class TestExceptionReporting(TestCase):
31
from breezy.sixish import PY3
32
from breezy.bzr.groupcompress_repo import RepositoryFormat2a
35
class TestExceptionReporting(tests.TestCaseInTempDir):
39
37
def test_exception_exitcode(self):
40
38
# we must use a subprocess, because the normal in-memory mechanism
43
41
universal_newlines=True,
44
42
retcode=errors.EXIT_INTERNAL_ERROR)
45
43
self.assertEqual(4, errors.EXIT_INTERNAL_ERROR)
46
self.assertContainsRe(err,
47
r'exceptions\.AssertionError: always fails\n')
48
self.assertContainsRe(err, r'Bazaar has encountered an internal error')
44
self.assertContainsRe(err, br'\nAssertionError: always fails\n')
45
self.assertContainsRe(err, br'Bazaar has encountered an internal error')
47
def test_undecodable_argv(self):
48
"""A user error must be reported if argv is not in the locale encoding
50
A subprocess with an environment ascii-only setting is used so the test
51
can run without worrying about the locale the test suite is using.
53
if os.name != "posix":
54
raise tests.TestNotApplicable("Needs system beholden to C locales")
56
raise tests.TestNotApplicable("Unable to pass argv to subprocess as bytes")
57
out, err = self.run_bzr_subprocess([b"\xa0"],
58
env_changes={"LANG": "C", "LC_ALL": "C"},
59
universal_newlines=True,
60
retcode=errors.EXIT_ERROR)
61
self.assertContainsRe(err, br"^brz: ERROR: .*'\\xa0'.* unsupported",
63
self.assertEqual(out, b"")
65
def test_utf8_default_fs_enc(self):
66
"""In the C locale brz treats a posix filesystem as UTF-8 encoded"""
67
if os.name != "posix":
68
raise tests.TestNotApplicable("Needs system beholden to C locales")
69
out, err = self.run_bzr_subprocess(["init", "file:%C2%A7"],
70
env_changes={"LANG": "C", "LC_ALL": "C"})
71
self.assertContainsRe(out, b"^Created a standalone tree .*$")
74
class TestOptParseBugHandling(tests.TestCase):
75
"Test that we handle http://bugs.python.org/issue2931"
77
def test_nonascii_optparse(self):
78
"""Reasonable error raised when non-ascii in option name on Python 2"""
80
error_re = u'no such option: -\xe4'
82
error_re = 'Only ASCII permitted in option names'
83
out = self.run_bzr_error([error_re], ['st', u'-\xe4'])
86
class TestObsoleteRepoFormat(RepositoryFormat2a):
89
def get_format_string(cls):
90
return b"Test Obsolete Repository Format"
92
def is_deprecated(self):
51
96
class TestDeprecationWarning(tests.TestCaseWithTransport):
52
97
"""The deprecation warning is controlled via a global variable:
53
98
repository._deprecation_warning_done. As such, it can be emitted only once
54
during a bzr invocation, no matter how many repositories are involved.
99
during a brz invocation, no matter how many repositories are involved.
56
101
It would be better if it was a repo attribute instead but that's far more
57
102
work than I want to do right now -- vila 20091215.
61
106
super(TestDeprecationWarning, self).setUp()
107
self.addCleanup(repository.format_registry.remove,
108
TestObsoleteRepoFormat)
109
repository.format_registry.register(TestObsoleteRepoFormat)
110
self.addCleanup(controldir.format_registry.remove, "testobsolete")
111
bzr.register_metadir(controldir.format_registry, "testobsolete",
112
"breezy.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
113
branch_format='breezy.bzr.branch.BzrBranchFormat7',
114
tree_format='breezy.bzr.workingtree_4.WorkingTreeFormat6',
116
help='Same as 2a, but with an obsolete repo format.')
62
117
self.disable_deprecation_warning()
64
119
def enable_deprecation_warning(self, repo=None):
72
127
def make_obsolete_repo(self, path):
73
128
# We don't want the deprecation raising during the repo creation
74
tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
129
format = controldir.format_registry.make_controldir("testobsolete")
130
tree = self.make_branch_and_tree(path, format=format)
77
133
def check_warning(self, present):
91
147
def test_repository_deprecation_warning_suppressed_global(self):
92
148
"""Old formats give a warning"""
93
conf = config.GlobalConfig()
94
conf.set_user_option('suppress_warnings', 'format_deprecation')
149
conf = config.GlobalStack()
150
conf.set('suppress_warnings', 'format_deprecation')
95
151
self.make_obsolete_repo('foo')
96
152
self.enable_deprecation_warning()
97
153
out, err = self.run_bzr('status', working_dir='foo')
100
156
def test_repository_deprecation_warning_suppressed_locations(self):
101
157
"""Old formats give a warning"""
102
158
self.make_obsolete_repo('foo')
103
conf = config.LocationConfig(osutils.pathjoin(self.test_dir, 'foo'))
104
conf.set_user_option('suppress_warnings', 'format_deprecation')
159
conf = config.LocationStack(osutils.pathjoin(self.test_dir, 'foo'))
160
conf.set('suppress_warnings', 'format_deprecation')
105
161
self.enable_deprecation_warning()
106
162
out, err = self.run_bzr('status', working_dir='foo')
107
163
self.check_warning(False)
109
165
def test_repository_deprecation_warning_suppressed_branch(self):
110
166
"""Old formats give a warning"""
111
167
tree = self.make_obsolete_repo('foo')
112
conf = tree.branch.get_config()
113
conf.set_user_option('suppress_warnings', 'format_deprecation')
168
conf = tree.branch.get_config_stack()
169
conf.set('suppress_warnings', 'format_deprecation')
114
170
self.enable_deprecation_warning()
115
171
out, err = self.run_bzr('status', working_dir='foo')
116
172
self.check_warning(False)