/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-10-31 22:28:29 UTC
  • mfrom: (2052.4.5 sftp-error-49172)
  • Revision ID: pqm@pqm.ubuntu.com-20061031222829-d691c81a8a20bdb0
(John Arbash Meinel) Fix bug #49172: nicer errors on sftp connection failure

Show diffs side-by-side

added added

removed removed

Lines of Context:
144
144
        e = errors.TransportNotPossible('readonly', 'original error')
145
145
        self.assertEqual('Transport operation not possible:'
146
146
                         ' readonly original error', str(e))
 
147
 
 
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))
 
152
 
 
153
    def test_socket_connection_error(self):
 
154
        """Test the formatting of SocketConnectionError"""
 
155
 
 
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',
 
160
            'ahost')
 
161
 
 
162
        # If port is None, we don't put :None
 
163
        self.assertSocketConnectionError(
 
164
            'Failed to connect to ahost',
 
165
            'ahost', port=None)
 
166
        # But if port is supplied we include it
 
167
        self.assertSocketConnectionError(
 
168
            'Failed to connect to ahost:22',
 
169
            'ahost', port=22)
 
170
 
 
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)
 
184
 
 
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')
 
190
 
 
191