92
92
e = errors.TransportNotPossible('readonly', 'original error')
93
93
self.assertEqual('Transport operation not possible:'
94
94
' readonly original error', str(e))
96
def assertSocketConnectionError(self, expected, *args, **kwargs):
97
"""Check the formatting of a SocketConnectionError exception"""
98
e = errors.SocketConnectionError(*args, **kwargs)
99
self.assertEqual(expected, str(e))
101
def test_socket_connection_error(self):
102
"""Test the formatting of SocketConnectionError"""
104
# There should be a default msg about failing to connect
105
# we only require a host name.
106
self.assertSocketConnectionError(
107
'Failed to connect to ahost',
110
# If port is None, we don't put :None
111
self.assertSocketConnectionError(
112
'Failed to connect to ahost',
114
# But if port is supplied we include it
115
self.assertSocketConnectionError(
116
'Failed to connect to ahost:22',
119
# We can also supply extra information about the error
120
# with or without a port
121
self.assertSocketConnectionError(
122
'Failed to connect to ahost:22; bogus error',
123
'ahost', port=22, orig_error='bogus error')
124
self.assertSocketConnectionError(
125
'Failed to connect to ahost; bogus error',
126
'ahost', orig_error='bogus error')
127
# An exception object can be passed rather than a string
128
orig_error = ValueError('bad value')
129
self.assertSocketConnectionError(
130
'Failed to connect to ahost; %s' % (str(orig_error),),
131
host='ahost', orig_error=orig_error)
133
# And we can supply a custom failure message
134
self.assertSocketConnectionError(
135
'Unable to connect to ssh host ahost:444; my_error',
136
host='ahost', port=444, msg='Unable to connect to ssh host',
137
orig_error='my_error')