17
17
"""Tests for display of exceptions."""
21
22
from bzrlib import (
30
from bzrlib.tests import TestCase
33
class TestExceptionReporting(TestCase):
31
from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
34
class TestExceptionReporting(tests.TestCaseInTempDir):
35
36
def test_exception_exitcode(self):
36
37
# we must use a subprocess, because the normal in-memory mechanism
43
44
r'exceptions\.AssertionError: always fails\n')
44
45
self.assertContainsRe(err, r'Bazaar has encountered an internal error')
47
class TestOptParseBugHandling(TestCase):
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")
55
out, err = self.run_bzr_subprocess(["\xa0"],
56
env_changes={"LANG": "C", "LC_ALL": "C"},
57
universal_newlines=True,
58
retcode=errors.EXIT_ERROR)
59
self.assertContainsRe(err, r"^bzr: ERROR: .*'\\xa0'.* unsupported",
61
self.assertEquals(out, "")
63
def test_utf8_default_fs_enc(self):
64
"""In the C locale bzr treats a posix filesystem as UTF-8 encoded"""
65
if os.name != "posix":
66
raise tests.TestNotApplicable("Needs system beholden to C locales")
67
out, err = self.run_bzr_subprocess(["init", "file:%C2%A7"],
68
env_changes={"LANG": "C", "LC_ALL": "C"})
69
self.assertContainsRe(out, "^Created a standalone tree .*$")
72
class TestOptParseBugHandling(tests.TestCase):
48
73
"Test that we handle http://bugs.python.org/issue2931"
50
75
def test_nonascii_optparse(self):
51
76
"""Reasonable error raised when non-ascii in option name"""
52
if sys.version_info < (2,5):
53
error_re = 'no such option'
55
error_re = 'Only ASCII permitted in option names'
77
error_re = 'Only ASCII permitted in option names'
56
78
out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
81
class TestObsoleteRepoFormat(RepositoryFormat2a):
84
def get_format_string(cls):
85
return "Test Obsolete Repository Format"
87
def is_deprecated(self):
59
91
class TestDeprecationWarning(tests.TestCaseWithTransport):
60
92
"""The deprecation warning is controlled via a global variable:
61
93
repository._deprecation_warning_done. As such, it can be emitted only once
69
101
super(TestDeprecationWarning, self).setUp()
102
self.addCleanup(repository.format_registry.remove,
103
TestObsoleteRepoFormat)
104
repository.format_registry.register(TestObsoleteRepoFormat)
105
self.addCleanup(controldir.format_registry.remove, "testobsolete")
106
bzrdir.register_metadir(controldir.format_registry, "testobsolete",
107
"bzrlib.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
108
branch_format='bzrlib.branch.BzrBranchFormat7',
109
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
111
help='Same as 2a, but with an obsolete repo format.')
70
112
self.disable_deprecation_warning()
72
114
def enable_deprecation_warning(self, repo=None):
80
122
def make_obsolete_repo(self, path):
81
123
# We don't want the deprecation raising during the repo creation
82
tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
124
format = controldir.format_registry.make_bzrdir("testobsolete")
125
tree = self.make_branch_and_tree(path, format=format)
85
128
def check_warning(self, present):
87
130
check = self.assertContainsRe
89
132
check = self.assertNotContainsRe
90
check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
133
check(self.get_log(), 'WARNING.*bzr upgrade')
92
135
def test_repository_deprecation_warning(self):
93
136
"""Old formats give a warning"""
99
142
def test_repository_deprecation_warning_suppressed_global(self):
100
143
"""Old formats give a warning"""
101
conf = config.GlobalConfig()
102
conf.set_user_option('suppress_warnings', 'format_deprecation')
144
conf = config.GlobalStack()
145
conf.set('suppress_warnings', 'format_deprecation')
103
146
self.make_obsolete_repo('foo')
104
147
self.enable_deprecation_warning()
105
148
out, err = self.run_bzr('status', working_dir='foo')
108
151
def test_repository_deprecation_warning_suppressed_locations(self):
109
152
"""Old formats give a warning"""
110
153
self.make_obsolete_repo('foo')
111
conf = config.LocationConfig(osutils.pathjoin(self.test_dir, 'foo'))
112
conf.set_user_option('suppress_warnings', 'format_deprecation')
154
conf = config.LocationStack(osutils.pathjoin(self.test_dir, 'foo'))
155
conf.set('suppress_warnings', 'format_deprecation')
113
156
self.enable_deprecation_warning()
114
157
out, err = self.run_bzr('status', working_dir='foo')
115
158
self.check_warning(False)
117
160
def test_repository_deprecation_warning_suppressed_branch(self):
118
161
"""Old formats give a warning"""
119
162
tree = self.make_obsolete_repo('foo')
120
conf = tree.branch.get_config()
121
conf.set_user_option('suppress_warnings', 'format_deprecation')
163
conf = tree.branch.get_config_stack()
164
conf.set('suppress_warnings', 'format_deprecation')
122
165
self.enable_deprecation_warning()
123
166
out, err = self.run_bzr('status', working_dir='foo')
124
167
self.check_warning(False)