/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: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

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
 
    )
34
31
 
35
32
 
36
33
class TestErrors(tests.TestCase):
48
45
            init = getattr(c, '__init__', None)
49
46
            fmt = getattr(c, '_fmt', None)
50
47
            if init:
51
 
                args = inspect.getargspec(init)[0]
 
48
                args = inspect.getfullargspec(init)[0]
52
49
                self.assertFalse('message' in args,
53
 
                    ('Argument name "message" not allowed for '
54
 
                    '"errors.%s.__init__"' % c.__name__))
 
50
                                 ('Argument name "message" not allowed for '
 
51
                                  '"errors.%s.__init__"' % c.__name__))
55
52
            if fmt and fmt_pattern.search(fmt):
56
53
                self.assertFalse(True, ('"message" not allowed in '
57
 
                    '"errors.%s._fmt"' % c.__name__))
 
54
                                        '"errors.%s._fmt"' % c.__name__))
58
55
 
59
56
    def test_bad_filename_encoding(self):
60
57
        error = errors.BadFilenameEncoding(b'bad/filen\xe5me', 'UTF-8')
71
68
    def test_duplicate_help_prefix(self):
72
69
        error = errors.DuplicateHelpPrefix('foo')
73
70
        self.assertEqualDiff('The prefix foo is in the help search path twice.',
74
 
            str(error))
 
71
                             str(error))
75
72
 
76
73
    def test_ghost_revisions_have_no_revno(self):
77
74
        error = errors.GhostRevisionsHaveNoRevno('target', 'ghost_rev')
81
78
 
82
79
    def test_incompatibleVersion(self):
83
80
        error = errors.IncompatibleVersion("module", [(4, 5, 6), (7, 8, 9)],
84
 
                (1, 2, 3))
 
81
                                           (1, 2, 3))
85
82
        self.assertEqualDiff(
86
83
            'API module is not compatible; one of versions '
87
84
            '[(4, 5, 6), (7, 8, 9)] is required, but current version is '
124
121
    def test_inventory_modified(self):
125
122
        error = errors.InventoryModified("a tree to be repred")
126
123
        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))
 
124
                             "be repred' has been modified, so a clean inventory cannot be "
 
125
                             "read without data loss.",
 
126
                             str(error))
130
127
 
131
128
    def test_jail_break(self):
132
129
        error = errors.JailBreak("some url")
133
130
        self.assertEqualDiff("An attempt to access a url outside the server"
134
 
            " jail was made: 'some url'.",
135
 
            str(error))
 
131
                             " jail was made: 'some url'.",
 
132
                             str(error))
136
133
 
137
134
    def test_lock_active(self):
138
135
        error = errors.LockActive("lock description")
139
136
        self.assertEqualDiff("The lock for 'lock description' is in use and "
140
 
            "cannot be broken.",
141
 
            str(error))
 
137
                             "cannot be broken.",
 
138
                             str(error))
142
139
 
143
140
    def test_lock_corrupt(self):
144
141
        error = errors.LockCorrupt("corruption info")
145
142
        self.assertEqualDiff("Lock is apparently held, but corrupted: "
146
 
            "corruption info\n"
147
 
            "Use 'brz break-lock' to clear it",
148
 
            str(error))
 
143
                             "corruption info\n"
 
144
                             "Use 'brz break-lock' to clear it",
 
145
                             str(error))
149
146
 
150
147
    def test_medium_not_connected(self):
151
148
        error = errors.MediumNotConnected("a medium")
155
152
    def test_no_smart_medium(self):
156
153
        error = errors.NoSmartMedium("a transport")
157
154
        self.assertEqualDiff("The transport 'a transport' cannot tunnel the "
158
 
            "smart protocol.",
159
 
            str(error))
 
155
                             "smart protocol.",
 
156
                             str(error))
160
157
 
161
158
    def test_no_such_id(self):
162
159
        error = errors.NoSuchId("atree", "anid")
163
160
        self.assertEqualDiff("The file id \"anid\" is not present in the tree "
164
 
            "atree.",
165
 
            str(error))
 
161
                             "atree.",
 
162
                             str(error))
166
163
 
167
164
    def test_no_such_revision_in_tree(self):
168
165
        error = errors.NoSuchRevisionInTree("atree", "anid")
173
170
    def test_not_stacked(self):
174
171
        error = errors.NotStacked('a branch')
175
172
        self.assertEqualDiff("The branch 'a branch' is not stacked.",
176
 
            str(error))
 
173
                             str(error))
177
174
 
178
175
    def test_not_write_locked(self):
179
176
        error = errors.NotWriteLocked('a thing to repr')
180
177
        self.assertEqualDiff("'a thing to repr' is not write locked but needs "
181
 
            "to be.",
182
 
            str(error))
 
178
                             "to be.",
 
179
                             str(error))
183
180
 
184
181
    def test_lock_failed(self):
185
 
        error = errors.LockFailed('http://canonical.com/', 'readonly transport')
 
182
        error = errors.LockFailed(
 
183
            'http://canonical.com/', 'readonly transport')
186
184
        self.assertEqualDiff("Cannot lock http://canonical.com/: readonly transport",
187
 
            str(error))
 
185
                             str(error))
188
186
        self.assertFalse(error.internal_error)
189
187
 
190
188
    def test_too_many_concurrent_requests(self):
191
189
        error = errors.TooManyConcurrentRequests("a medium")
192
190
        self.assertEqualDiff("The medium 'a medium' has reached its concurrent "
193
 
            "request limit. Be sure to finish_writing and finish_reading on "
194
 
            "the currently open request.",
195
 
            str(error))
 
191
                             "request limit. Be sure to finish_writing and finish_reading on "
 
192
                             "the currently open request.",
 
193
                             str(error))
196
194
 
197
195
    def test_unavailable_representation(self):
198
 
        error = errors.UnavailableRepresentation(('key',), "mpdiff", "fulltext")
 
196
        error = errors.UnavailableRepresentation(
 
197
            ('key',), "mpdiff", "fulltext")
199
198
        self.assertEqualDiff("The encoding 'mpdiff' is not available for key "
200
 
            "('key',) which is encoded as 'fulltext'.",
201
 
            str(error))
 
199
                             "('key',) which is encoded as 'fulltext'.",
 
200
                             str(error))
202
201
 
203
202
    def test_unstackable_location(self):
204
203
        error = errors.UnstackableLocationError('foo', 'bar')
205
204
        self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
206
 
            str(error))
 
205
                             str(error))
207
206
 
208
207
    def test_unstackable_repository_format(self):
209
208
        format = u'foo'
239
238
    def test_reading_completed(self):
240
239
        error = errors.ReadingCompleted("a request")
241
240
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
242
 
            "finish_reading called upon it - the request has been completed and"
243
 
            " no more data may be read.",
244
 
            str(error))
 
241
                             "finish_reading called upon it - the request has been completed and"
 
242
                             " no more data may be read.",
 
243
                             str(error))
245
244
 
246
245
    def test_writing_completed(self):
247
246
        error = errors.WritingCompleted("a request")
248
247
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
249
 
            "finish_writing called upon it - accept bytes may not be called "
250
 
            "anymore.",
251
 
            str(error))
 
248
                             "finish_writing called upon it - accept bytes may not be called "
 
249
                             "anymore.",
 
250
                             str(error))
252
251
 
253
252
    def test_writing_not_completed(self):
254
253
        error = errors.WritingNotComplete("a request")
255
254
        self.assertEqualDiff("The MediumRequest 'a request' has not has "
256
 
            "finish_writing called upon it - until the write phase is complete"
257
 
            " no data may be read.",
258
 
            str(error))
 
255
                             "finish_writing called upon it - until the write phase is complete"
 
256
                             " no data may be read.",
 
257
                             str(error))
259
258
 
260
259
    def test_transport_not_possible(self):
261
260
        error = errors.TransportNotPossible('readonly', 'original error')
262
261
        self.assertEqualDiff('Transport operation not possible:'
263
 
                         ' readonly original error', str(error))
 
262
                             ' readonly original error', str(error))
264
263
 
265
264
    def assertSocketConnectionError(self, expected, *args, **kwargs):
266
265
        """Check the formatting of a SocketConnectionError exception"""
359
358
        e = errors.DuplicateRecordNameError(b"n\xc3\xa5me")
360
359
        self.assertEqual(
361
360
            u"Container has multiple records with the same name: n\xe5me",
362
 
            text_type(e))
 
361
            str(e))
363
362
 
364
363
    def test_check_error(self):
365
364
        e = errors.BzrCheckError('example check failure')
382
381
            "you wish to keep, and delete it when you are done.",
383
382
            str(err))
384
383
 
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
 
 
399
384
    def test_invalid_url_join(self):
400
385
        """Test the formatting of InvalidURLJoin."""
401
386
        e = urlutils.InvalidURLJoin('Reason', 'base path', ('args',))
417
402
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
418
403
        self.assertEqual(
419
404
            u'Tip change rejected: Unicode message\N{INTERROBANG}',
420
 
            text_type(err))
 
405
            str(err))
421
406
 
422
407
    def test_error_from_smart_server(self):
423
408
        error_tuple = ('error', 'tuple')
477
462
    def test_recursive_bind(self):
478
463
        error = errors.RecursiveBind('foo_bar_branch')
479
464
        msg = ('Branch "foo_bar_branch" appears to be bound to itself. '
480
 
            'Please use `brz unbind` to fix.')
 
465
               'Please use `brz unbind` to fix.')
481
466
        self.assertEqualDiff(msg, str(error))
482
467
 
483
468
    def test_retry_with_new_packs(self):
511
496
    def test_always_str(self):
512
497
        e = PassThroughError(u'\xb5', 'bar')
513
498
        self.assertIsInstance(e.__str__(), str)
514
 
        # In Python str(foo) *must* return a real byte string
 
499
        # In Python 2 str(foo) *must* return a real byte string
515
500
        # not a Unicode string. The following line would raise a
516
501
        # Unicode error, because it tries to call str() on the string
517
502
        # returned from e.__str__(), and it has non ascii characters
518
503
        s = str(e)
519
 
        self.assertEqual('Pass through \xc2\xb5 and bar', s)
 
504
        self.assertEqual('Pass through \xb5 and bar', s)
520
505
 
521
506
    def test_missing_format_string(self):
522
507
        e = ErrorWithNoFormat(param='randomvalue')
559
544
    def test_no_repo(self):
560
545
        dir = controldir.ControlDir.create(self.get_url())
561
546
        error = errors.NoRepositoryPresent(dir)
562
 
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
 
547
        self.assertNotEqual(-1,
 
548
                            str(error).find((dir.transport.clone('..').base)))
563
549
        self.assertEqual(-1, str(error).find((dir.transport.base)))
564
550
 
565
551
    def test_corrupt_repository(self):
583
569
 
584
570
    def test_not_branch_laziness(self):
585
571
        real_bzrdir = self.make_controldir('path')
 
572
 
586
573
        class FakeBzrDir(object):
587
574
            def __init__(self):
588
575
                self.calls = []
 
576
 
589
577
            def open_repository(self):
590
578
                self.calls.append('open_repository')
591
579
                raise errors.NoRepositoryPresent(real_bzrdir)