52
67
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}",
55
76
def test_incompatibleAPI(self):
56
77
error = errors.IncompatibleAPI("module", (1, 2, 3), (4, 5, 6), (7, 8, 9))
57
78
self.assertEqualDiff(
93
114
"read without data loss.",
96
def test_install_failed(self):
97
error = errors.InstallFailed(['rev-one'])
98
self.assertEqual("Could not install revisions:\nrev-one", str(error))
99
error = errors.InstallFailed(['rev-one', 'rev-two'])
100
self.assertEqual("Could not install revisions:\nrev-one, rev-two",
102
error = errors.InstallFailed([None])
103
self.assertEqual("Could not install revisions:\nNone", str(error))
117
def test_jail_break(self):
118
error = errors.JailBreak("some url")
119
self.assertEqualDiff("An attempt to access a url outside the server"
120
" jail was made: 'some url'.",
105
123
def test_lock_active(self):
106
124
error = errors.LockActive("lock description")
370
388
host='ahost', port=444, msg='Unable to connect to ssh host',
371
389
orig_error='my_error')
391
def test_target_not_branch(self):
392
"""Test the formatting of TargetNotBranch."""
393
error = errors.TargetNotBranch('foo')
395
"Your branch does not have all of the revisions required in "
396
"order to merge this merge directive and the target "
397
"location specified in the merge directive is not a branch: "
373
400
def test_malformed_bug_identifier(self):
374
401
"""Test the formatting of MalformedBugIdentifier."""
375
402
error = errors.MalformedBugIdentifier('bogus', 'reason for bogosity')
376
403
self.assertEqual(
377
"Did not understand bug identifier bogus: reason for bogosity",
404
'Did not understand bug identifier bogus: reason for bogosity. '
405
'See "bzr help bugs" for more information on this feature.',
380
408
def test_unknown_bug_tracker_abbreviation(self):
493
521
err = errors.UnknownFormatError('bar', kind='foo')
494
522
self.assertEquals("Unknown foo format: 'bar'", str(err))
524
def test_unknown_rules(self):
525
err = errors.UnknownRules(['foo', 'bar'])
526
self.assertEquals("Unknown rules detected: foo, bar.", str(err))
528
def test_hook_failed(self):
529
# Create an exc_info tuple by raising and catching an exception.
532
except ZeroDivisionError:
533
exc_info = sys.exc_info()
534
err = errors.HookFailed('hook stage', 'hook name', exc_info)
535
self.assertStartsWith(
536
str(err), 'Hook \'hook name\' during hook stage failed:\n')
538
str(err), 'integer division or modulo by zero')
540
def test_tip_change_rejected(self):
541
err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
543
u'Tip change rejected: Unicode message\N{INTERROBANG}',
546
'Tip change rejected: Unicode message\xe2\x80\xbd',
549
def test_error_from_smart_server(self):
550
error_tuple = ('error', 'tuple')
551
err = errors.ErrorFromSmartServer(error_tuple)
553
"Error received from smart server: ('error', 'tuple')", str(err))
555
def test_untranslateable_error_from_smart_server(self):
556
error_tuple = ('error', 'tuple')
557
orig_err = errors.ErrorFromSmartServer(error_tuple)
558
err = errors.UnknownErrorFromSmartServer(orig_err)
560
"Server sent an unexpected error: ('error', 'tuple')", str(err))
562
def test_smart_message_handler_error(self):
563
# Make an exc_info tuple.
565
raise Exception("example error")
567
exc_info = sys.exc_info()
568
err = errors.SmartMessageHandlerError(exc_info)
569
self.assertStartsWith(
570
str(err), "The message handler raised an exception:\n")
571
self.assertEndsWith(str(err), "Exception: example error\n")
573
def test_must_have_working_tree(self):
574
err = errors.MustHaveWorkingTree('foo', 'bar')
575
self.assertEqual(str(err), "Branching 'bar'(foo) must create a"
578
def test_no_such_view(self):
579
err = errors.NoSuchView('foo')
580
self.assertEquals("No such view: foo.", str(err))
582
def test_views_not_supported(self):
583
err = errors.ViewsNotSupported('atree')
585
self.assertStartsWith(err_str, "Views are not supported by ")
586
self.assertEndsWith(err_str, "; use 'bzr upgrade' to change your "
587
"tree to a later format.")
589
def test_file_outside_view(self):
590
err = errors.FileOutsideView('baz', ['foo', 'bar'])
591
self.assertEquals('Specified file "baz" is outside the current view: '
592
'foo, bar', str(err))
594
def test_invalid_shelf_id(self):
596
err = errors.InvalidShelfId(invalid_id)
597
self.assertEqual('"foo" is not a valid shelf id, '
598
'try a number instead.', str(err))
600
def test_unresumable_write_group(self):
602
wg_tokens = ['token']
604
err = errors.UnresumableWriteGroup(repo, wg_tokens, reason)
606
"Repository dummy repo cannot resume write group "
607
"['token']: a reason", str(err))
609
def test_unsuspendable_write_group(self):
611
err = errors.UnsuspendableWriteGroup(repo)
613
'Repository dummy repo cannot suspend a write group.', str(err))
497
616
class PassThroughError(errors.BzrError):
499
618
_fmt = """Pass through %(foo)s and %(bar)s"""
501
620
def __init__(self, foo, bar):