45
48
init = getattr(c, '__init__', None)
46
49
fmt = getattr(c, '_fmt', None)
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__))
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$")
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))
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.',
68
76
def test_ghost_revisions_have_no_revno(self):
69
77
error = errors.GhostRevisionsHaveNoRevno('target', 'ghost_rev')
74
82
def test_incompatibleVersion(self):
75
83
error = errors.IncompatibleVersion("module", [(4, 5, 6), (7, 8, 9)],
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",
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.",
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'.",
134
" jail was made: 'some url'.",
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 "
128
143
def test_lock_corrupt(self):
129
144
error = errors.LockCorrupt("corruption info")
130
145
self.assertEqualDiff("Lock is apparently held, but corrupted: "
132
"Use 'brz break-lock' to clear it",
147
"Use 'brz break-lock' to clear it",
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 "
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 "
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.",
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 "
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",
174
188
self.assertFalse(error.internal_error)
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.",
193
"request limit. Be sure to finish_writing and finish_reading on "
194
"the currently open request.",
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'.",
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'.",
188
208
def test_unstackable_repository_format(self):
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.",
242
"finish_reading called upon it - the request has been completed and"
243
" no more data may be read.",
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 "
249
"finish_writing called upon it - accept bytes may not be called "
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.",
256
"finish_writing called upon it - until the write phase is complete"
257
" no data may be read.",
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))
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",
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.",
385
def test_unable_create_symlink(self):
386
err = errors.UnableCreateSymlink()
388
"Unable to create symlink on this platform",
390
err = errors.UnableCreateSymlink(path=u'foo')
392
"Unable to create symlink 'foo' on this platform",
394
err = errors.UnableCreateSymlink(path=u'\xb5')
396
"Unable to create symlink %s on this platform" % repr(u'\xb5'),
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}',
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))
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
485
self.assertEqual('Pass through \xb5 and bar', s)
519
self.assertEqual('Pass through \xc2\xb5 and bar', s)
487
521
def test_missing_format_string(self):
488
522
e = ErrorWithNoFormat(param='randomvalue')
506
540
r'Cannot bind address "example\.com:22":.*Permission denied')
542
def test_transform_rename_failed(self):
543
e = errors.TransformRenameFailed(u"from", u"to", "readonly file", 2)
545
u"Failed to rename from to to: readonly file",
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)))
526
565
def test_corrupt_repository(self):
545
584
def test_not_branch_laziness(self):
546
585
real_bzrdir = self.make_controldir('path')
548
586
class FakeBzrDir(object):
549
587
def __init__(self):
552
589
def open_repository(self):
553
590
self.calls.append('open_repository')
554
591
raise errors.NoRepositoryPresent(real_bzrdir)