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))
40
49
def test_medium_not_connected(self):
41
50
error = errors.MediumNotConnected("a medium")
42
51
self.assertEqualDiff(
126
135
" no data may be read.",
138
def test_transport_not_possible(self):
139
e = errors.TransportNotPossible('readonly', 'original error')
140
self.assertEqual('Transport operation not possible:'
141
' readonly original error', str(e))
143
def assertSocketConnectionError(self, expected, *args, **kwargs):
144
"""Check the formatting of a SocketConnectionError exception"""
145
e = errors.SocketConnectionError(*args, **kwargs)
146
self.assertEqual(expected, str(e))
148
def test_socket_connection_error(self):
149
"""Test the formatting of SocketConnectionError"""
151
# There should be a default msg about failing to connect
152
# we only require a host name.
153
self.assertSocketConnectionError(
154
'Failed to connect to ahost',
157
# If port is None, we don't put :None
158
self.assertSocketConnectionError(
159
'Failed to connect to ahost',
161
# But if port is supplied we include it
162
self.assertSocketConnectionError(
163
'Failed to connect to ahost:22',
166
# We can also supply extra information about the error
167
# with or without a port
168
self.assertSocketConnectionError(
169
'Failed to connect to ahost:22; bogus error',
170
'ahost', port=22, orig_error='bogus error')
171
self.assertSocketConnectionError(
172
'Failed to connect to ahost; bogus error',
173
'ahost', orig_error='bogus error')
174
# An exception object can be passed rather than a string
175
orig_error = ValueError('bad value')
176
self.assertSocketConnectionError(
177
'Failed to connect to ahost; %s' % (str(orig_error),),
178
host='ahost', orig_error=orig_error)
180
# And we can supply a custom failure message
181
self.assertSocketConnectionError(
182
'Unable to connect to ssh host ahost:444; my_error',
183
host='ahost', port=444, msg='Unable to connect to ssh host',
184
orig_error='my_error')
130
188
class PassThroughError(errors.BzrError):
173
231
self.assertStartsWith(
174
232
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')