/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: John Arbash Meinel
  • Date: 2006-09-29 21:13:35 UTC
  • mto: This revision was merged to the branch mainline in revision 2110.
  • Revision ID: john@arbash-meinel.com-20060929211335-9af4fcf54348644e
Create a SocketConnectionError to make creating nice errors easier

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
        e = errors.TransportNotPossible('readonly', 'original error')
93
93
        self.assertEqual('Transport operation not possible:'
94
94
                         ' readonly original error', str(e))
 
95
 
 
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))
 
100
 
 
101
    def test_socket_connection_error(self):
 
102
        """Test the formatting of SocketConnectionError"""
 
103
 
 
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',
 
108
            'ahost')
 
109
 
 
110
        # If port is None, we don't put :None
 
111
        self.assertSocketConnectionError(
 
112
            'Failed to connect to ahost',
 
113
            'ahost', port=None)
 
114
        # But if port is supplied we include it
 
115
        self.assertSocketConnectionError(
 
116
            'Failed to connect to ahost:22',
 
117
            'ahost', port=22)
 
118
 
 
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)
 
132
 
 
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')
 
138
 
 
139