114
120
"read without data loss.",
117
def test_install_failed(self):
118
error = errors.InstallFailed(['rev-one'])
119
self.assertEqual("Could not install revisions:\nrev-one", str(error))
120
error = errors.InstallFailed(['rev-one', 'rev-two'])
121
self.assertEqual("Could not install revisions:\nrev-one, rev-two",
123
error = errors.InstallFailed([None])
124
self.assertEqual("Could not install revisions:\nNone", str(error))
123
def test_jail_break(self):
124
error = errors.JailBreak("some url")
125
self.assertEqualDiff("An attempt to access a url outside the server"
126
" jail was made: 'some url'.",
126
129
def test_lock_active(self):
127
130
error = errors.LockActive("lock description")
548
557
'Tip change rejected: Unicode message\xe2\x80\xbd',
560
def test_error_from_smart_server(self):
561
error_tuple = ('error', 'tuple')
562
err = errors.ErrorFromSmartServer(error_tuple)
564
"Error received from smart server: ('error', 'tuple')", str(err))
566
def test_untranslateable_error_from_smart_server(self):
567
error_tuple = ('error', 'tuple')
568
orig_err = errors.ErrorFromSmartServer(error_tuple)
569
err = errors.UnknownErrorFromSmartServer(orig_err)
571
"Server sent an unexpected error: ('error', 'tuple')", str(err))
573
def test_smart_message_handler_error(self):
574
# Make an exc_info tuple.
576
raise Exception("example error")
578
exc_info = sys.exc_info()
579
err = errors.SmartMessageHandlerError(exc_info)
580
self.assertStartsWith(
581
str(err), "The message handler raised an exception:\n")
582
self.assertEndsWith(str(err), "Exception: example error\n")
584
def test_must_have_working_tree(self):
585
err = errors.MustHaveWorkingTree('foo', 'bar')
586
self.assertEqual(str(err), "Branching 'bar'(foo) must create a"
589
def test_no_such_view(self):
590
err = errors.NoSuchView('foo')
591
self.assertEquals("No such view: foo.", str(err))
593
def test_views_not_supported(self):
594
err = errors.ViewsNotSupported('atree')
596
self.assertStartsWith(err_str, "Views are not supported by ")
597
self.assertEndsWith(err_str, "; use 'bzr upgrade' to change your "
598
"tree to a later format.")
600
def test_file_outside_view(self):
601
err = errors.FileOutsideView('baz', ['foo', 'bar'])
602
self.assertEquals('Specified file "baz" is outside the current view: '
603
'foo, bar', str(err))
605
def test_invalid_shelf_id(self):
607
err = errors.InvalidShelfId(invalid_id)
608
self.assertEqual('"foo" is not a valid shelf id, '
609
'try a number instead.', str(err))
611
def test_unresumable_write_group(self):
613
wg_tokens = ['token']
615
err = errors.UnresumableWriteGroup(repo, wg_tokens, reason)
617
"Repository dummy repo cannot resume write group "
618
"['token']: a reason", str(err))
620
def test_unsuspendable_write_group(self):
622
err = errors.UnsuspendableWriteGroup(repo)
624
'Repository dummy repo cannot suspend a write group.', str(err))
626
def test_not_branch_no_args(self):
627
err = errors.NotBranchError('path')
628
self.assertEqual('Not a branch: "path".', str(err))
630
def test_not_branch_bzrdir_with_repo(self):
631
bzrdir = self.make_repository('repo').bzrdir
632
err = errors.NotBranchError('path', bzrdir=bzrdir)
634
'Not a branch: "path": location is a repository.', str(err))
636
def test_not_branch_bzrdir_without_repo(self):
637
bzrdir = self.make_bzrdir('bzrdir')
638
err = errors.NotBranchError('path', bzrdir=bzrdir)
639
self.assertEqual('Not a branch: "path".', str(err))
641
def test_not_branch_laziness(self):
642
real_bzrdir = self.make_bzrdir('path')
643
class FakeBzrDir(object):
646
def open_repository(self):
647
self.calls.append('open_repository')
648
raise errors.NoRepositoryPresent(real_bzrdir)
649
fake_bzrdir = FakeBzrDir()
650
err = errors.NotBranchError('path', bzrdir=fake_bzrdir)
651
self.assertEqual([], fake_bzrdir.calls)
653
self.assertEqual(['open_repository'], fake_bzrdir.calls)
654
# Stringifying twice doesn't try to open a repository twice.
656
self.assertEqual(['open_repository'], fake_bzrdir.calls)
552
659
class PassThroughError(errors.BzrError):
554
661
_fmt = """Pass through %(foo)s and %(bar)s"""
556
663
def __init__(self, foo, bar):
594
701
e = ErrorWithBadFormat(not_thing='x')
595
702
self.assertStartsWith(
596
703
str(e), 'Unprintable exception ErrorWithBadFormat')
705
def test_cannot_bind_address(self):
706
# see <https://bugs.edge.launchpad.net/bzr/+bug/286871>
707
e = errors.CannotBindAddress('example.com', 22,
708
socket.error(13, 'Permission denied'))
709
self.assertContainsRe(str(e),
710
r'Cannot bind address "example\.com:22":.*Permission denied')
712
def test_file_timestamp_unavailable(self):
713
e = errors.FileTimestampUnavailable("/path/foo")
714
self.assertEquals("The filestamp for /path/foo is not available.",