49
48
init = getattr(c, '__init__', None)
50
49
fmt = getattr(c, '_fmt', None)
53
args = inspect.getfullargspec(init)[0]
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__))
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.',
80
76
def test_ghost_revisions_have_no_revno(self):
81
77
error = errors.GhostRevisionsHaveNoRevno('target', 'ghost_rev')
86
82
def test_incompatibleVersion(self):
87
83
error = errors.IncompatibleVersion("module", [(4, 5, 6), (7, 8, 9)],
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.",
127
"be repred' has been modified, so a clean inventory cannot be "
128
"read without data loss.",
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'.",
134
" jail was made: 'some url'.",
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 "
147
143
def test_lock_corrupt(self):
148
144
error = errors.LockCorrupt("corruption info")
149
145
self.assertEqualDiff("Lock is apparently held, but corrupted: "
151
"Use 'brz break-lock' to clear it",
147
"Use 'brz break-lock' to clear it",
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 "
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 "
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.",
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 "
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",
193
188
self.assertFalse(error.internal_error)
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.",
193
"request limit. Be sure to finish_writing and finish_reading on "
194
"the currently open request.",
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'.",
200
"('key',) which is encoded as 'fulltext'.",
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'.",
214
208
def test_unstackable_repository_format(self):
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.",
242
"finish_reading called upon it - the request has been completed and"
243
" no more data may be read.",
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 "
249
"finish_writing called upon it - accept bytes may not be called "
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.",
256
"finish_writing called upon it - until the write phase is complete"
257
" no data may be read.",
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))
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.",
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'),
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))
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
512
self.assertEqual('Pass through \xb5 and bar', s)
514
self.assertEqual('Pass through \xc2\xb5 and bar', s)
519
self.assertEqual('Pass through \xc2\xb5 and bar', s)
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)))
561
565
def test_corrupt_repository(self):
580
584
def test_not_branch_laziness(self):
581
585
real_bzrdir = self.make_controldir('path')
583
586
class FakeBzrDir(object):
584
587
def __init__(self):
587
589
def open_repository(self):
588
590
self.calls.append('open_repository')
589
591
raise errors.NoRepositoryPresent(real_bzrdir)