32
31
class TestErrors(TestCaseWithTransport):
34
def test_bad_filename_encoding(self):
35
error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
37
"Filename 'bad/filen\\xe5me' is not valid in your current"
38
" filesystem encoding UTF-8",
41
33
def test_corrupt_dirstate(self):
42
34
error = errors.CorruptDirstate('path/to/dirstate', 'the reason why')
43
35
self.assertEqualDiff(
45
37
"Error: the reason why",
48
def test_dirstate_corrupt(self):
49
error = errors.DirstateCorrupt('.bzr/checkout/dirstate',
50
'trailing garbage: "x"')
51
self.assertEqualDiff("The dirstate file (.bzr/checkout/dirstate)"
52
" appears to be corrupt: trailing garbage: \"x\"",
55
40
def test_disabled_method(self):
56
41
error = errors.DisabledMethod("class name")
57
42
self.assertEqualDiff(
67
52
self.assertEqualDiff('The prefix foo is in the help search path twice.',
70
def test_ghost_revisions_have_no_revno(self):
71
error = errors.GhostRevisionsHaveNoRevno('target', 'ghost_rev')
72
self.assertEqualDiff("Could not determine revno for {target} because"
73
" its ancestry shows a ghost at {ghost_rev}",
76
55
def test_incompatibleAPI(self):
77
56
error = errors.IncompatibleAPI("module", (1, 2, 3), (4, 5, 6), (7, 8, 9))
78
57
self.assertEqualDiff(
196
175
" tree atree.", str(error))
197
176
self.assertIsInstance(error, errors.NoSuchRevision)
199
def test_not_stacked(self):
200
error = errors.NotStacked('a branch')
201
self.assertEqualDiff("The branch 'a branch' is not stacked.",
204
178
def test_not_write_locked(self):
205
179
error = errors.NotWriteLocked('a thing to repr')
206
180
self.assertEqualDiff("'a thing to repr' is not write locked but needs "
184
def test_read_only_lock_error(self):
185
error = self.applyDeprecated(symbol_versioning.zero_ninetytwo,
186
errors.ReadOnlyLockError, 'filename', 'error message')
187
self.assertEqualDiff("Cannot acquire write lock on filename."
188
" error message", str(error))
210
190
def test_lock_failed(self):
211
191
error = errors.LockFailed('http://canonical.com/', 'readonly transport')
212
192
self.assertEqualDiff("Cannot lock http://canonical.com/: readonly transport",
220
200
"the currently open request.",
223
def test_unavailable_representation(self):
224
error = errors.UnavailableRepresentation(('key',), "mpdiff", "fulltext")
225
self.assertEqualDiff("The encoding 'mpdiff' is not available for key "
226
"('key',) which is encoded as 'fulltext'.",
229
203
def test_unknown_hook(self):
230
204
error = errors.UnknownHook("branch", "foo")
231
205
self.assertEqualDiff("The branch hook 'foo' is unknown in this version"
239
def test_unstackable_branch_format(self):
242
error = errors.UnstackableBranchFormat(format, url)
243
self.assertEqualDiff(
244
"The branch '/foo'(foo) is not a stackable format. "
245
"You will need to upgrade the branch to permit branch stacking.",
248
def test_unstackable_repository_format(self):
251
error = errors.UnstackableRepositoryFormat(format, url)
252
self.assertEqualDiff(
253
"The repository '/foo'(foo) is not a stackable format. "
254
"You will need to upgrade the repository to permit branch stacking.",
257
213
def test_up_to_date(self):
258
214
error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
259
215
self.assertEqualDiff("The branch format Bazaar-NG branch, "
391
347
host='ahost', port=444, msg='Unable to connect to ssh host',
392
348
orig_error='my_error')
394
def test_target_not_branch(self):
395
"""Test the formatting of TargetNotBranch."""
396
error = errors.TargetNotBranch('foo')
398
"Your branch does not have all of the revisions required in "
399
"order to merge this merge directive and the target "
400
"location specified in the merge directive is not a branch: "
403
350
def test_malformed_bug_identifier(self):
404
351
"""Test the formatting of MalformedBugIdentifier."""
405
352
error = errors.MalformedBugIdentifier('bogus', 'reason for bogosity')
499
446
"Unable to create symlink u'\\xb5' on this platform",
502
def test_invalid_url_join(self):
503
"""Test the formatting of InvalidURLJoin."""
504
e = errors.InvalidURLJoin('Reason', 'base path', ('args',))
506
"Invalid URL join request: Reason: 'base path' + ('args',)",
509
449
def test_incorrect_url(self):
510
450
err = errors.InvalidBugTrackerURL('foo', 'http://bug.com/')
511
451
self.assertEquals(
523
463
err = errors.UnknownFormatError('bar', kind='foo')
524
464
self.assertEquals("Unknown foo format: 'bar'", str(err))
526
def test_unknown_rules(self):
527
err = errors.UnknownRules(['foo', 'bar'])
528
self.assertEquals("Unknown rules detected: foo, bar.", str(err))
530
def test_hook_failed(self):
531
# Create an exc_info tuple by raising and catching an exception.
534
except ZeroDivisionError:
535
exc_info = sys.exc_info()
536
err = errors.HookFailed('hook stage', 'hook name', exc_info)
537
self.assertStartsWith(
538
str(err), 'Hook \'hook name\' during hook stage failed:\n')
540
str(err), 'integer division or modulo by zero')
542
def test_tip_change_rejected(self):
543
err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
545
u'Tip change rejected: Unicode message\N{INTERROBANG}',
548
'Tip change rejected: Unicode message\xe2\x80\xbd',
551
def test_error_from_smart_server(self):
552
error_tuple = ('error', 'tuple')
553
err = errors.ErrorFromSmartServer(error_tuple)
555
"Error received from smart server: ('error', 'tuple')", str(err))
557
def test_untranslateable_error_from_smart_server(self):
558
error_tuple = ('error', 'tuple')
559
orig_err = errors.ErrorFromSmartServer(error_tuple)
560
err = errors.UnknownErrorFromSmartServer(orig_err)
562
"Server sent an unexpected error: ('error', 'tuple')", str(err))
565
467
class PassThroughError(errors.BzrError):