/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-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    urlutils,
30
30
    )
31
31
from ..sixish import (
32
 
    PY3,
33
32
    text_type,
34
33
    )
35
34
 
49
48
            init = getattr(c, '__init__', None)
50
49
            fmt = getattr(c, '_fmt', None)
51
50
            if init:
52
 
                if PY3:
53
 
                    args = inspect.getfullargspec(init)[0]
54
 
                else:
55
 
                    args = inspect.getargspec(init)[0]
 
51
                args = inspect.getargspec(init)[0]
56
52
                self.assertFalse('message' in args,
57
 
                                 ('Argument name "message" not allowed for '
58
 
                                  '"errors.%s.__init__"' % c.__name__))
 
53
                    ('Argument name "message" not allowed for '
 
54
                    '"errors.%s.__init__"' % c.__name__))
59
55
            if fmt and fmt_pattern.search(fmt):
60
56
                self.assertFalse(True, ('"message" not allowed in '
61
 
                                        '"errors.%s._fmt"' % c.__name__))
 
57
                    '"errors.%s._fmt"' % c.__name__))
62
58
 
63
59
    def test_bad_filename_encoding(self):
64
60
        error = errors.BadFilenameEncoding(b'bad/filen\xe5me', 'UTF-8')
75
71
    def test_duplicate_help_prefix(self):
76
72
        error = errors.DuplicateHelpPrefix('foo')
77
73
        self.assertEqualDiff('The prefix foo is in the help search path twice.',
78
 
                             str(error))
 
74
            str(error))
79
75
 
80
76
    def test_ghost_revisions_have_no_revno(self):
81
77
        error = errors.GhostRevisionsHaveNoRevno('target', 'ghost_rev')
85
81
 
86
82
    def test_incompatibleVersion(self):
87
83
        error = errors.IncompatibleVersion("module", [(4, 5, 6), (7, 8, 9)],
88
 
                                           (1, 2, 3))
 
84
                (1, 2, 3))
89
85
        self.assertEqualDiff(
90
86
            'API module is not compatible; one of versions '
91
87
            '[(4, 5, 6), (7, 8, 9)] is required, but current version is '
128
124
    def test_inventory_modified(self):
129
125
        error = errors.InventoryModified("a tree to be repred")
130
126
        self.assertEqualDiff("The current inventory for the tree 'a tree to "
131
 
                             "be repred' has been modified, so a clean inventory cannot be "
132
 
                             "read without data loss.",
133
 
                             str(error))
 
127
            "be repred' has been modified, so a clean inventory cannot be "
 
128
            "read without data loss.",
 
129
            str(error))
134
130
 
135
131
    def test_jail_break(self):
136
132
        error = errors.JailBreak("some url")
137
133
        self.assertEqualDiff("An attempt to access a url outside the server"
138
 
                             " jail was made: 'some url'.",
139
 
                             str(error))
 
134
            " jail was made: 'some url'.",
 
135
            str(error))
140
136
 
141
137
    def test_lock_active(self):
142
138
        error = errors.LockActive("lock description")
143
139
        self.assertEqualDiff("The lock for 'lock description' is in use and "
144
 
                             "cannot be broken.",
145
 
                             str(error))
 
140
            "cannot be broken.",
 
141
            str(error))
146
142
 
147
143
    def test_lock_corrupt(self):
148
144
        error = errors.LockCorrupt("corruption info")
149
145
        self.assertEqualDiff("Lock is apparently held, but corrupted: "
150
 
                             "corruption info\n"
151
 
                             "Use 'brz break-lock' to clear it",
152
 
                             str(error))
 
146
            "corruption info\n"
 
147
            "Use 'brz break-lock' to clear it",
 
148
            str(error))
153
149
 
154
150
    def test_medium_not_connected(self):
155
151
        error = errors.MediumNotConnected("a medium")
159
155
    def test_no_smart_medium(self):
160
156
        error = errors.NoSmartMedium("a transport")
161
157
        self.assertEqualDiff("The transport 'a transport' cannot tunnel the "
162
 
                             "smart protocol.",
163
 
                             str(error))
 
158
            "smart protocol.",
 
159
            str(error))
164
160
 
165
161
    def test_no_such_id(self):
166
162
        error = errors.NoSuchId("atree", "anid")
167
163
        self.assertEqualDiff("The file id \"anid\" is not present in the tree "
168
 
                             "atree.",
169
 
                             str(error))
 
164
            "atree.",
 
165
            str(error))
170
166
 
171
167
    def test_no_such_revision_in_tree(self):
172
168
        error = errors.NoSuchRevisionInTree("atree", "anid")
177
173
    def test_not_stacked(self):
178
174
        error = errors.NotStacked('a branch')
179
175
        self.assertEqualDiff("The branch 'a branch' is not stacked.",
180
 
                             str(error))
 
176
            str(error))
181
177
 
182
178
    def test_not_write_locked(self):
183
179
        error = errors.NotWriteLocked('a thing to repr')
184
180
        self.assertEqualDiff("'a thing to repr' is not write locked but needs "
185
 
                             "to be.",
186
 
                             str(error))
 
181
            "to be.",
 
182
            str(error))
187
183
 
188
184
    def test_lock_failed(self):
189
 
        error = errors.LockFailed(
190
 
            'http://canonical.com/', 'readonly transport')
 
185
        error = errors.LockFailed('http://canonical.com/', 'readonly transport')
191
186
        self.assertEqualDiff("Cannot lock http://canonical.com/: readonly transport",
192
 
                             str(error))
 
187
            str(error))
193
188
        self.assertFalse(error.internal_error)
194
189
 
195
190
    def test_too_many_concurrent_requests(self):
196
191
        error = errors.TooManyConcurrentRequests("a medium")
197
192
        self.assertEqualDiff("The medium 'a medium' has reached its concurrent "
198
 
                             "request limit. Be sure to finish_writing and finish_reading on "
199
 
                             "the currently open request.",
200
 
                             str(error))
 
193
            "request limit. Be sure to finish_writing and finish_reading on "
 
194
            "the currently open request.",
 
195
            str(error))
201
196
 
202
197
    def test_unavailable_representation(self):
203
 
        error = errors.UnavailableRepresentation(
204
 
            ('key',), "mpdiff", "fulltext")
 
198
        error = errors.UnavailableRepresentation(('key',), "mpdiff", "fulltext")
205
199
        self.assertEqualDiff("The encoding 'mpdiff' is not available for key "
206
 
                             "('key',) which is encoded as 'fulltext'.",
207
 
                             str(error))
 
200
            "('key',) which is encoded as 'fulltext'.",
 
201
            str(error))
208
202
 
209
203
    def test_unstackable_location(self):
210
204
        error = errors.UnstackableLocationError('foo', 'bar')
211
205
        self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
212
 
                             str(error))
 
206
            str(error))
213
207
 
214
208
    def test_unstackable_repository_format(self):
215
209
        format = u'foo'
245
239
    def test_reading_completed(self):
246
240
        error = errors.ReadingCompleted("a request")
247
241
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
248
 
                             "finish_reading called upon it - the request has been completed and"
249
 
                             " no more data may be read.",
250
 
                             str(error))
 
242
            "finish_reading called upon it - the request has been completed and"
 
243
            " no more data may be read.",
 
244
            str(error))
251
245
 
252
246
    def test_writing_completed(self):
253
247
        error = errors.WritingCompleted("a request")
254
248
        self.assertEqualDiff("The MediumRequest 'a request' has already had "
255
 
                             "finish_writing called upon it - accept bytes may not be called "
256
 
                             "anymore.",
257
 
                             str(error))
 
249
            "finish_writing called upon it - accept bytes may not be called "
 
250
            "anymore.",
 
251
            str(error))
258
252
 
259
253
    def test_writing_not_completed(self):
260
254
        error = errors.WritingNotComplete("a request")
261
255
        self.assertEqualDiff("The MediumRequest 'a request' has not has "
262
 
                             "finish_writing called upon it - until the write phase is complete"
263
 
                             " no data may be read.",
264
 
                             str(error))
 
256
            "finish_writing called upon it - until the write phase is complete"
 
257
            " no data may be read.",
 
258
            str(error))
265
259
 
266
260
    def test_transport_not_possible(self):
267
261
        error = errors.TransportNotPossible('readonly', 'original error')
268
262
        self.assertEqualDiff('Transport operation not possible:'
269
 
                             ' readonly original error', str(error))
 
263
                         ' readonly original error', str(error))
270
264
 
271
265
    def assertSocketConnectionError(self, expected, *args, **kwargs):
272
266
        """Check the formatting of a SocketConnectionError exception"""
388
382
            "you wish to keep, and delete it when you are done.",
389
383
            str(err))
390
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
 
391
399
    def test_invalid_url_join(self):
392
400
        """Test the formatting of InvalidURLJoin."""
393
401
        e = urlutils.InvalidURLJoin('Reason', 'base path', ('args',))
469
477
    def test_recursive_bind(self):
470
478
        error = errors.RecursiveBind('foo_bar_branch')
471
479
        msg = ('Branch "foo_bar_branch" appears to be bound to itself. '
472
 
               'Please use `brz unbind` to fix.')
 
480
            'Please use `brz unbind` to fix.')
473
481
        self.assertEqualDiff(msg, str(error))
474
482
 
475
483
    def test_retry_with_new_packs(self):
503
511
    def test_always_str(self):
504
512
        e = PassThroughError(u'\xb5', 'bar')
505
513
        self.assertIsInstance(e.__str__(), str)
506
 
        # In Python 2 str(foo) *must* return a real byte string
 
514
        # In Python str(foo) *must* return a real byte string
507
515
        # not a Unicode string. The following line would raise a
508
516
        # Unicode error, because it tries to call str() on the string
509
517
        # returned from e.__str__(), and it has non ascii characters
510
518
        s = str(e)
511
 
        if PY3:
512
 
            self.assertEqual('Pass through \xb5 and bar', s)
513
 
        else:
514
 
            self.assertEqual('Pass through \xc2\xb5 and bar', s)
 
519
        self.assertEqual('Pass through \xc2\xb5 and bar', s)
515
520
 
516
521
    def test_missing_format_string(self):
517
522
        e = ErrorWithNoFormat(param='randomvalue')
554
559
    def test_no_repo(self):
555
560
        dir = controldir.ControlDir.create(self.get_url())
556
561
        error = errors.NoRepositoryPresent(dir)
557
 
        self.assertNotEqual(-1,
558
 
                            str(error).find((dir.transport.clone('..').base)))
 
562
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
559
563
        self.assertEqual(-1, str(error).find((dir.transport.base)))
560
564
 
561
565
    def test_corrupt_repository(self):
579
583
 
580
584
    def test_not_branch_laziness(self):
581
585
        real_bzrdir = self.make_controldir('path')
582
 
 
583
586
        class FakeBzrDir(object):
584
587
            def __init__(self):
585
588
                self.calls = []
586
 
 
587
589
            def open_repository(self):
588
590
                self.calls.append('open_repository')
589
591
                raise errors.NoRepositoryPresent(real_bzrdir)