48
45
init = getattr(c, '__init__', None)
49
46
fmt = getattr(c, '_fmt', None)
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__))
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.',
76
73
def test_ghost_revisions_have_no_revno(self):
77
74
error = errors.GhostRevisionsHaveNoRevno('target', 'ghost_rev')
82
79
def test_incompatibleVersion(self):
83
80
error = errors.IncompatibleVersion("module", [(4, 5, 6), (7, 8, 9)],
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.",
124
"be repred' has been modified, so a clean inventory cannot be "
125
"read without data loss.",
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'.",
131
" jail was made: 'some url'.",
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 "
143
140
def test_lock_corrupt(self):
144
141
error = errors.LockCorrupt("corruption info")
145
142
self.assertEqualDiff("Lock is apparently held, but corrupted: "
147
"Use 'brz break-lock' to clear it",
144
"Use 'brz break-lock' to clear it",
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 "
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 "
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.",
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 "
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",
188
186
self.assertFalse(error.internal_error)
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.",
191
"request limit. Be sure to finish_writing and finish_reading on "
192
"the currently open request.",
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'.",
199
"('key',) which is encoded as 'fulltext'.",
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'.",
208
207
def test_unstackable_repository_format(self):
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.",
241
"finish_reading called upon it - the request has been completed and"
242
" no more data may be read.",
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 "
248
"finish_writing called upon it - accept bytes may not be called "
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.",
255
"finish_writing called upon it - until the write phase is complete"
256
" no data may be read.",
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))
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",
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.",
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'),
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}',
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))
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
519
self.assertEqual('Pass through \xc2\xb5 and bar', s)
504
self.assertEqual('Pass through \xb5 and bar', s)
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)))
565
551
def test_corrupt_repository(self):
584
570
def test_not_branch_laziness(self):
585
571
real_bzrdir = self.make_controldir('path')
586
573
class FakeBzrDir(object):
587
574
def __init__(self):
589
577
def open_repository(self):
590
578
self.calls.append('open_repository')
591
579
raise errors.NoRepositoryPresent(real_bzrdir)