37
37
"read without data loss.",
40
def test_install_failed(self):
41
error = errors.InstallFailed(['rev-one'])
42
self.assertEqual("Could not install revisions:\nrev-one", str(error))
43
error = errors.InstallFailed(['rev-one', 'rev-two'])
44
self.assertEqual("Could not install revisions:\nrev-one, rev-two",
46
error = errors.InstallFailed([None])
47
self.assertEqual("Could not install revisions:\nNone", str(error))
49
def test_knit_header_error(self):
50
error = errors.KnitHeaderError('line foo\n', 'path/to/file')
51
self.assertEqual("Knit header error: 'line foo\\n' unexpected"
52
" for file path/to/file", str(error))
54
def test_knit_index_unknown_method(self):
55
error = errors.KnitIndexUnknownMethod('http://host/foo.kndx',
57
self.assertEqual("Knit index http://host/foo.kndx does not have a"
58
" known method in options: ['bad', 'no-eol']",
40
61
def test_medium_not_connected(self):
41
62
error = errors.MediumNotConnected("a medium")
42
63
self.assertEqualDiff(
73
94
"the current request that is open.",
97
def test_unknown_hook(self):
98
error = errors.UnknownHook("branch", "foo")
99
self.assertEqualDiff("The branch hook 'foo' is unknown in this version"
102
error = errors.UnknownHook("tree", "bar")
103
self.assertEqualDiff("The tree hook 'bar' is unknown in this version"
76
107
def test_up_to_date(self):
77
108
error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
78
109
self.assertEqualDiff("The branch format Bazaar-NG branch, "
126
157
" no data may be read.",
160
def test_transport_not_possible(self):
161
e = errors.TransportNotPossible('readonly', 'original error')
162
self.assertEqual('Transport operation not possible:'
163
' readonly original error', str(e))
165
def assertSocketConnectionError(self, expected, *args, **kwargs):
166
"""Check the formatting of a SocketConnectionError exception"""
167
e = errors.SocketConnectionError(*args, **kwargs)
168
self.assertEqual(expected, str(e))
170
def test_socket_connection_error(self):
171
"""Test the formatting of SocketConnectionError"""
173
# There should be a default msg about failing to connect
174
# we only require a host name.
175
self.assertSocketConnectionError(
176
'Failed to connect to ahost',
179
# If port is None, we don't put :None
180
self.assertSocketConnectionError(
181
'Failed to connect to ahost',
183
# But if port is supplied we include it
184
self.assertSocketConnectionError(
185
'Failed to connect to ahost:22',
188
# We can also supply extra information about the error
189
# with or without a port
190
self.assertSocketConnectionError(
191
'Failed to connect to ahost:22; bogus error',
192
'ahost', port=22, orig_error='bogus error')
193
self.assertSocketConnectionError(
194
'Failed to connect to ahost; bogus error',
195
'ahost', orig_error='bogus error')
196
# An exception object can be passed rather than a string
197
orig_error = ValueError('bad value')
198
self.assertSocketConnectionError(
199
'Failed to connect to ahost; %s' % (str(orig_error),),
200
host='ahost', orig_error=orig_error)
202
# And we can supply a custom failure message
203
self.assertSocketConnectionError(
204
'Unable to connect to ssh host ahost:444; my_error',
205
host='ahost', port=444, msg='Unable to connect to ssh host',
206
orig_error='my_error')
130
210
class PassThroughError(errors.BzrError):
173
253
self.assertStartsWith(
174
254
str(e), 'Unprintable exception ErrorWithBadFormat')
177
class TestSpecificErrors(TestCase):
179
def test_transport_not_possible(self):
180
e = errors.TransportNotPossible('readonly', 'original error')
181
self.assertEqual('Transport operation not possible:'
182
' readonly original error', str(e))
184
def assertSocketConnectionError(self, expected, *args, **kwargs):
185
"""Check the formatting of a SocketConnectionError exception"""
186
e = errors.SocketConnectionError(*args, **kwargs)
187
self.assertEqual(expected, str(e))
189
def test_socket_connection_error(self):
190
"""Test the formatting of SocketConnectionError"""
192
# There should be a default msg about failing to connect
193
# we only require a host name.
194
self.assertSocketConnectionError(
195
'Failed to connect to ahost',
198
# If port is None, we don't put :None
199
self.assertSocketConnectionError(
200
'Failed to connect to ahost',
202
# But if port is supplied we include it
203
self.assertSocketConnectionError(
204
'Failed to connect to ahost:22',
207
# We can also supply extra information about the error
208
# with or without a port
209
self.assertSocketConnectionError(
210
'Failed to connect to ahost:22; bogus error',
211
'ahost', port=22, orig_error='bogus error')
212
self.assertSocketConnectionError(
213
'Failed to connect to ahost; bogus error',
214
'ahost', orig_error='bogus error')
215
# An exception object can be passed rather than a string
216
orig_error = ValueError('bad value')
217
self.assertSocketConnectionError(
218
'Failed to connect to ahost; %s' % (str(orig_error),),
219
host='ahost', orig_error=orig_error)
221
# And we can supply a custom failure message
222
self.assertSocketConnectionError(
223
'Unable to connect to ssh host ahost:444; my_error',
224
host='ahost', port=444, msg='Unable to connect to ssh host',
225
orig_error='my_error')