17
17
"""Tests for display of exceptions."""
22
21
from bzrlib import (
31
from bzrlib.repofmt.groupcompress_repo import RepositoryFormat2a
34
class TestExceptionReporting(tests.TestCaseInTempDir):
30
from bzrlib.tests import TestCase
33
class TestExceptionReporting(TestCase):
36
35
def test_exception_exitcode(self):
37
36
# we must use a subprocess, because the normal in-memory mechanism
44
43
r'exceptions\.AssertionError: always fails\n')
45
44
self.assertContainsRe(err, r'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")
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, "")
64
class TestOptParseBugHandling(tests.TestCase):
47
class TestOptParseBugHandling(TestCase):
65
48
"Test that we handle http://bugs.python.org/issue2931"
67
50
def test_nonascii_optparse(self):
68
51
"""Reasonable error raised when non-ascii in option name"""
69
error_re = 'Only ASCII permitted in option names'
52
if sys.version_info < (2,5):
53
error_re = 'no such option'
55
error_re = 'Only ASCII permitted in option names'
70
56
out = self.run_bzr_error([error_re], ['st',u'-\xe4'])
73
class TestObsoleteRepoFormat(RepositoryFormat2a):
76
def get_format_string(cls):
77
return "Test Obsolete Repository Format"
79
def is_deprecated(self):
83
59
class TestDeprecationWarning(tests.TestCaseWithTransport):
84
60
"""The deprecation warning is controlled via a global variable:
85
61
repository._deprecation_warning_done. As such, it can be emitted only once
93
69
super(TestDeprecationWarning, self).setUp()
94
self.addCleanup(repository.format_registry.remove,
95
TestObsoleteRepoFormat)
96
repository.format_registry.register(TestObsoleteRepoFormat)
97
self.addCleanup(controldir.format_registry.remove, "testobsolete")
98
bzrdir.register_metadir(controldir.format_registry, "testobsolete",
99
"bzrlib.tests.blackbox.test_exceptions.TestObsoleteRepoFormat",
100
branch_format='bzrlib.branch.BzrBranchFormat7',
101
tree_format='bzrlib.workingtree_4.WorkingTreeFormat6',
103
help='Same as 2a, but with an obsolete repo format.')
104
70
self.disable_deprecation_warning()
106
72
def enable_deprecation_warning(self, repo=None):
114
80
def make_obsolete_repo(self, path):
115
81
# We don't want the deprecation raising during the repo creation
116
format = controldir.format_registry.make_bzrdir("testobsolete")
117
tree = self.make_branch_and_tree(path, format=format)
82
tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
120
85
def check_warning(self, present):
122
87
check = self.assertContainsRe
124
89
check = self.assertNotContainsRe
125
check(self.get_log(), 'WARNING.*bzr upgrade')
90
check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
127
92
def test_repository_deprecation_warning(self):
128
93
"""Old formats give a warning"""