/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 breezy/tests/test_errors.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    tests,
29
29
    urlutils,
30
30
    )
 
31
from ..sixish import (
 
32
    text_type,
 
33
    )
31
34
 
32
35
 
33
36
class TestErrors(tests.TestCase):
45
48
            init = getattr(c, '__init__', None)
46
49
            fmt = getattr(c, '_fmt', None)
47
50
            if init:
48
 
                args = inspect.getfullargspec(init)[0]
 
51
                args = inspect.getargspec(init)[0]
49
52
                self.assertFalse('message' in args,
50
 
                                 ('Argument name "message" not allowed for '
51
 
                                  '"errors.%s.__init__"' % c.__name__))
 
53
                    ('Argument name "message" not allowed for '
 
54
                    '"errors.%s.__init__"' % c.__name__))
52
55
            if fmt and fmt_pattern.search(fmt):
53
56
                self.assertFalse(True, ('"message" not allowed in '
54
 
                                        '"errors.%s._fmt"' % c.__name__))
 
57
                    '"errors.%s._fmt"' % c.__name__))
55
58
 
56
59
    def test_bad_filename_encoding(self):
57
60
        error = errors.BadFilenameEncoding(b'bad/filen\xe5me', 'UTF-8')
60
63
            "^Filename b?'bad/filen\\\\xe5me' is not valid in your current"
61
64
            " filesystem encoding UTF-8$")
62
65
 
 
66
    def test_duplicate_file_id(self):
 
67
        error = errors.DuplicateFileId('a_file_id', 'foo')
 
68
        self.assertEqualDiff('File id {a_file_id} already exists in inventory'
 
69
                             ' as foo', str(error))
 
70
 
63
71
    def test_duplicate_help_prefix(self):
64
72
        error = errors.DuplicateHelpPrefix('foo')
65
73
        self.assertEqualDiff('The prefix foo is in the help search path twice.',
66
 
                             str(error))
 
74
            str(error))
67
75
 
68
76
    def test_ghost_revisions_have_no_revno(self):
69
77
        error = errors.GhostRevisionsHaveNoRevno('target', 'ghost_rev')
73
81
 
74
82
    def test_incompatibleVersion(self):
75
83
        error = errors.IncompatibleVersion("module", [(4, 5, 6), (7, 8, 9)],
76
 
                                           (1, 2, 3))
 
84
                (1, 2, 3))
77
85
        self.assertEqualDiff(
78
86
            'API module is not compatible; one of versions '
79
87
            '[(4, 5, 6), (7, 8, 9)] is required, but current version is '
113
121
        self.assertEqual("Invalid range access in path at 12: bad range",
114
122
                         str(error))
115
123
 
 
124
    def test_inventory_modified(self):
 
125
        error = errors.InventoryModified("a tree to be repred")
 
126
        self.assertEqualDiff("The current inventory for the tree 'a tree to "
 
127
            "be repred' has been modified, so a clean inventory cannot be "
 
128
            "read without data loss.",
 
129
            str(error))
 
130
 
116
131
    def test_jail_break(self):
117
132
        error = errors.JailBreak("some url")
118
133
        self.assertEqualDiff("An attempt to access a url outside the server"
119
 
                             " jail was made: 'some url'.",
120
 
                             str(error))
 
134
            " jail was made: 'some url'.",
 
135
            str(error))
121
136
 
122
137
    def test_lock_active(self):
123
138
        error = errors.LockActive("lock description")
124
139
        self.assertEqualDiff("The lock for 'lock description' is in use and "
125
 
                             "cannot be broken.",
126
 
                             str(error))
 
140
            "cannot be broken.",
 
141
            str(error))
127
142
 
128
143
    def test_lock_corrupt(self):
129
144
        error = errors.LockCorrupt("corruption info")
130
145
        self.assertEqualDiff("Lock is apparently held, but corrupted: "
131
 
                             "corruption info\n"
132
 
                             "Use 'brz break-lock' to clear it",
133
 
                             str(error))
 
146
            "corruption info\n"
 
147
            "Use 'brz break-lock' to clear it",
 
148
            str(error))
134
149
 
135
150
    def test_medium_not_connected(self):
136
151
        error = errors.MediumNotConnected("a medium")
140
155
    def test_no_smart_medium(self):
141
156
        error = errors.NoSmartMedium("a transport")
142
157
        self.assertEqualDiff("The transport 'a transport' cannot tunnel the "
143
 
                             "smart protocol.",
144
 
                             str(error))
 
158
            "smart protocol.",
 
159
            str(error))
145
160
 
146
161
    def test_no_such_id(self):
147
162
        error = errors.NoSuchId("atree", "anid")
148
163
        self.assertEqualDiff("The file id \"anid\" is not present in the tree "
149
 
                             "atree.",
150
 
                             str(error))
 
164
            "atree.",
 
165
            str(error))
151
166
 
152
167
    def test_no_such_revision_in_tree(self):
153
168
        error = errors.NoSuchRevisionInTree("atree", "anid")
158
173
    def test_not_stacked(self):
159
174
        error = errors.NotStacked('a branch')
160
175
        self.assertEqualDiff("The branch 'a branch' is not stacked.",
161
 
                             str(error))
 
176
            str(error))
162
177
 
163
178
    def test_not_write_locked(self):
164
179
        error = errors.NotWriteLocked('a thing to repr')
165
180
        self.assertEqualDiff("'a thing to repr' is not write locked but needs "
166
 
                             "to be.",
167
 
                             str(error))
 
181
            "to be.",
 
182
            str(error))
168
183
 
169
184
    def test_lock_failed(self):
170
 
        error = errors.LockFailed(
171
 
            'http://canonical.com/', 'readonly transport')
 
185
        error = errors.LockFailed('http://canonical.com/', 'readonly transport')
172
186
        self.assertEqualDiff("Cannot lock http://canonical.com/: readonly transport",
173
 
                             str(error))
 
187
            str(error))
174
188
        self.assertFalse(error.internal_error)
175
189
 
176
190
    def test_too_many_concurrent_requests(self):
177
191
        error = errors.TooManyConcurrentRequests("a medium")
178
192
        self.assertEqualDiff("The medium 'a medium' has reached its concurrent "
179
 
                             "request limit. Be sure to finish_writing and finish_reading on "
180
 
                             "the currently open request.",
181
 
                             str(error))
 
193
            "request limit. Be sure to finish_writing and finish_reading on "
 
194
            "the currently open request.",
 
195
            str(error))
 
196
 
 
197
    def test_unavailable_representation(self):
 
198
        error = errors.UnavailableRepresentation(('key',), "mpdiff", "fulltext")
 
199
        self.assertEqualDiff("The encoding 'mpdiff' is not available for key "
 
200
            "('key',) which is encoded as 'fulltext'.",
 
201
            str(error))
182
202
 
183
203
    def test_unstackable_location(self):
184
204
        error = errors.UnstackableLocationError('foo', 'bar')
185
205
        self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
186
 
                             str(error))
 
206
            str(error))
187
207
 
188
208
    def test_unstackable_repository_format(self):
189
209
        format = u'foo'
219
239
    def test_reading_completed(self):
220
240
        error = errors.ReadingCompleted("a request")
221
241
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
222
 
                             "finish_reading called upon it - the request has been completed and"
223
 
                             " no more data may be read.",
224
 
                             str(error))
 
242
            "finish_reading called upon it - the request has been completed and"
 
243
            " no more data may be read.",
 
244
            str(error))
225
245
 
226
246
    def test_writing_completed(self):
227
247
        error = errors.WritingCompleted("a request")
228
248
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
229
 
                             "finish_writing called upon it - accept bytes may not be called "
230
 
                             "anymore.",
231
 
                             str(error))
 
249
            "finish_writing called upon it - accept bytes may not be called "
 
250
            "anymore.",
 
251
            str(error))
232
252
 
233
253
    def test_writing_not_completed(self):
234
254
        error = errors.WritingNotComplete("a request")
235
255
        self.assertEqualDiff("The MediumRequest 'a request' has not has "
236
 
                             "finish_writing called upon it - until the write phase is complete"
237
 
                             " no data may be read.",
238
 
                             str(error))
 
256
            "finish_writing called upon it - until the write phase is complete"
 
257
            " no data may be read.",
 
258
            str(error))
239
259
 
240
260
    def test_transport_not_possible(self):
241
261
        error = errors.TransportNotPossible('readonly', 'original error')
242
262
        self.assertEqualDiff('Transport operation not possible:'
243
 
                             ' readonly original error', str(error))
 
263
                         ' readonly original error', str(error))
244
264
 
245
265
    def assertSocketConnectionError(self, expected, *args, **kwargs):
246
266
        """Check the formatting of a SocketConnectionError exception"""
339
359
        e = errors.DuplicateRecordNameError(b"n\xc3\xa5me")
340
360
        self.assertEqual(
341
361
            u"Container has multiple records with the same name: n\xe5me",
342
 
            str(e))
 
362
            text_type(e))
343
363
 
344
364
    def test_check_error(self):
345
365
        e = errors.BzrCheckError('example check failure')
362
382
            "you wish to keep, and delete it when you are done.",
363
383
            str(err))
364
384
 
 
385
    def test_unable_create_symlink(self):
 
386
        err = errors.UnableCreateSymlink()
 
387
        self.assertEqual(
 
388
            "Unable to create symlink on this platform",
 
389
            str(err))
 
390
        err = errors.UnableCreateSymlink(path=u'foo')
 
391
        self.assertEqual(
 
392
            "Unable to create symlink 'foo' on this platform",
 
393
            str(err))
 
394
        err = errors.UnableCreateSymlink(path=u'\xb5')
 
395
        self.assertEqual(
 
396
            "Unable to create symlink %s on this platform" % repr(u'\xb5'),
 
397
            str(err))
 
398
 
365
399
    def test_invalid_url_join(self):
366
400
        """Test the formatting of InvalidURLJoin."""
367
401
        e = urlutils.InvalidURLJoin('Reason', 'base path', ('args',))
383
417
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
384
418
        self.assertEqual(
385
419
            u'Tip change rejected: Unicode message\N{INTERROBANG}',
386
 
            str(err))
 
420
            text_type(err))
387
421
 
388
422
    def test_error_from_smart_server(self):
389
423
        error_tuple = ('error', 'tuple')
443
477
    def test_recursive_bind(self):
444
478
        error = errors.RecursiveBind('foo_bar_branch')
445
479
        msg = ('Branch "foo_bar_branch" appears to be bound to itself. '
446
 
               'Please use `brz unbind` to fix.')
 
480
            'Please use `brz unbind` to fix.')
447
481
        self.assertEqualDiff(msg, str(error))
448
482
 
449
483
    def test_retry_with_new_packs(self):
477
511
    def test_always_str(self):
478
512
        e = PassThroughError(u'\xb5', 'bar')
479
513
        self.assertIsInstance(e.__str__(), str)
480
 
        # In Python 2 str(foo) *must* return a real byte string
 
514
        # In Python str(foo) *must* return a real byte string
481
515
        # not a Unicode string. The following line would raise a
482
516
        # Unicode error, because it tries to call str() on the string
483
517
        # returned from e.__str__(), and it has non ascii characters
484
518
        s = str(e)
485
 
        self.assertEqual('Pass through \xb5 and bar', s)
 
519
        self.assertEqual('Pass through \xc2\xb5 and bar', s)
486
520
 
487
521
    def test_missing_format_string(self):
488
522
        e = ErrorWithNoFormat(param='randomvalue')
505
539
            str(e),
506
540
            r'Cannot bind address "example\.com:22":.*Permission denied')
507
541
 
 
542
    def test_transform_rename_failed(self):
 
543
        e = errors.TransformRenameFailed(u"from", u"to", "readonly file", 2)
 
544
        self.assertEqual(
 
545
            u"Failed to rename from to to: readonly file",
 
546
            str(e))
 
547
 
508
548
 
509
549
class TestErrorsUsingTransport(tests.TestCaseWithMemoryTransport):
510
550
    """Tests for errors that need to use a branch or repo."""
519
559
    def test_no_repo(self):
520
560
        dir = controldir.ControlDir.create(self.get_url())
521
561
        error = errors.NoRepositoryPresent(dir)
522
 
        self.assertNotEqual(-1,
523
 
                            str(error).find((dir.transport.clone('..').base)))
 
562
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
524
563
        self.assertEqual(-1, str(error).find((dir.transport.base)))
525
564
 
526
565
    def test_corrupt_repository(self):
544
583
 
545
584
    def test_not_branch_laziness(self):
546
585
        real_bzrdir = self.make_controldir('path')
547
 
 
548
586
        class FakeBzrDir(object):
549
587
            def __init__(self):
550
588
                self.calls = []
551
 
 
552
589
            def open_repository(self):
553
590
                self.calls.append('open_repository')
554
591
                raise errors.NoRepositoryPresent(real_bzrdir)