144
144
e = errors.TransportNotPossible('readonly', 'original error')
145
145
self.assertEqual('Transport operation not possible:'
146
146
' readonly original error', str(e))
148
def assertSocketConnectionError(self, expected, *args, **kwargs):
149
"""Check the formatting of a SocketConnectionError exception"""
150
e = errors.SocketConnectionError(*args, **kwargs)
151
self.assertEqual(expected, str(e))
153
def test_socket_connection_error(self):
154
"""Test the formatting of SocketConnectionError"""
156
# There should be a default msg about failing to connect
157
# we only require a host name.
158
self.assertSocketConnectionError(
159
'Failed to connect to ahost',
162
# If port is None, we don't put :None
163
self.assertSocketConnectionError(
164
'Failed to connect to ahost',
166
# But if port is supplied we include it
167
self.assertSocketConnectionError(
168
'Failed to connect to ahost:22',
171
# We can also supply extra information about the error
172
# with or without a port
173
self.assertSocketConnectionError(
174
'Failed to connect to ahost:22; bogus error',
175
'ahost', port=22, orig_error='bogus error')
176
self.assertSocketConnectionError(
177
'Failed to connect to ahost; bogus error',
178
'ahost', orig_error='bogus error')
179
# An exception object can be passed rather than a string
180
orig_error = ValueError('bad value')
181
self.assertSocketConnectionError(
182
'Failed to connect to ahost; %s' % (str(orig_error),),
183
host='ahost', orig_error=orig_error)
185
# And we can supply a custom failure message
186
self.assertSocketConnectionError(
187
'Unable to connect to ssh host ahost:444; my_error',
188
host='ahost', port=444, msg='Unable to connect to ssh host',
189
orig_error='my_error')