/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: Aaron Bentley
  • Date: 2007-03-03 17:17:53 UTC
  • mfrom: (2309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2316.
  • Revision ID: aaron.bentley@utoronto.ca-20070303171753-o0s1yrxx5sn12p2k
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
            "read without data loss.",
38
38
            str(error))
39
39
 
 
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",
 
45
                         str(error))
 
46
        error = errors.InstallFailed([None])
 
47
        self.assertEqual("Could not install revisions:\nNone", str(error))
 
48
 
 
49
    def test_knit_header_error(self):
 
50
        error = errors.KnitHeaderError('line foo\n', 'path/to/file')
 
51
        self.assertEqual("Knit header error: 'line foo\\n' unexpected"
 
52
                         " for file path/to/file", str(error))
 
53
 
 
54
    def test_knit_index_unknown_method(self):
 
55
        error = errors.KnitIndexUnknownMethod('http://host/foo.kndx',
 
56
                                              ['bad', 'no-eol'])
 
57
        self.assertEqual("Knit index http://host/foo.kndx does not have a"
 
58
                         " known method in options: ['bad', 'no-eol']",
 
59
                         str(error))
 
60
 
40
61
    def test_medium_not_connected(self):
41
62
        error = errors.MediumNotConnected("a medium")
42
63
        self.assertEqualDiff(
73
94
            "the current request that is open.",
74
95
            str(error))
75
96
 
 
97
    def test_unknown_hook(self):
 
98
        error = errors.UnknownHook("branch", "foo")
 
99
        self.assertEqualDiff("The branch hook 'foo' is unknown in this version"
 
100
            " of bzrlib.",
 
101
            str(error))
 
102
        error = errors.UnknownHook("tree", "bar")
 
103
        self.assertEqualDiff("The tree hook 'bar' is unknown in this version"
 
104
            " of bzrlib.",
 
105
            str(error))
 
106
 
76
107
    def test_up_to_date(self):
77
108
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
78
109
        self.assertEqualDiff("The branch format Bazaar-NG branch, "
126
157
            " no data may be read.",
127
158
            str(error))
128
159
 
 
160
    def test_transport_not_possible(self):
 
161
        e = errors.TransportNotPossible('readonly', 'original error')
 
162
        self.assertEqual('Transport operation not possible:'
 
163
                         ' readonly original error', str(e))
 
164
 
 
165
    def assertSocketConnectionError(self, expected, *args, **kwargs):
 
166
        """Check the formatting of a SocketConnectionError exception"""
 
167
        e = errors.SocketConnectionError(*args, **kwargs)
 
168
        self.assertEqual(expected, str(e))
 
169
 
 
170
    def test_socket_connection_error(self):
 
171
        """Test the formatting of SocketConnectionError"""
 
172
 
 
173
        # There should be a default msg about failing to connect
 
174
        # we only require a host name.
 
175
        self.assertSocketConnectionError(
 
176
            'Failed to connect to ahost',
 
177
            'ahost')
 
178
 
 
179
        # If port is None, we don't put :None
 
180
        self.assertSocketConnectionError(
 
181
            'Failed to connect to ahost',
 
182
            'ahost', port=None)
 
183
        # But if port is supplied we include it
 
184
        self.assertSocketConnectionError(
 
185
            'Failed to connect to ahost:22',
 
186
            'ahost', port=22)
 
187
 
 
188
        # We can also supply extra information about the error
 
189
        # with or without a port
 
190
        self.assertSocketConnectionError(
 
191
            'Failed to connect to ahost:22; bogus error',
 
192
            'ahost', port=22, orig_error='bogus error')
 
193
        self.assertSocketConnectionError(
 
194
            'Failed to connect to ahost; bogus error',
 
195
            'ahost', orig_error='bogus error')
 
196
        # An exception object can be passed rather than a string
 
197
        orig_error = ValueError('bad value')
 
198
        self.assertSocketConnectionError(
 
199
            'Failed to connect to ahost; %s' % (str(orig_error),),
 
200
            host='ahost', orig_error=orig_error)
 
201
 
 
202
        # And we can supply a custom failure message
 
203
        self.assertSocketConnectionError(
 
204
            'Unable to connect to ssh host ahost:444; my_error',
 
205
            host='ahost', port=444, msg='Unable to connect to ssh host',
 
206
            orig_error='my_error')
 
207
 
 
208
 
129
209
 
130
210
class PassThroughError(errors.BzrError):
131
211
    
173
253
        self.assertStartsWith(
174
254
            str(e), 'Unprintable exception ErrorWithBadFormat')
175
255
 
176
 
 
177
 
class TestSpecificErrors(TestCase):
178
 
    
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))
183
 
 
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))
188
 
 
189
 
    def test_socket_connection_error(self):
190
 
        """Test the formatting of SocketConnectionError"""
191
 
 
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',
196
 
            'ahost')
197
 
 
198
 
        # If port is None, we don't put :None
199
 
        self.assertSocketConnectionError(
200
 
            'Failed to connect to ahost',
201
 
            'ahost', port=None)
202
 
        # But if port is supplied we include it
203
 
        self.assertSocketConnectionError(
204
 
            'Failed to connect to ahost:22',
205
 
            'ahost', port=22)
206
 
 
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)
220
 
 
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')
226
 
 
227