1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
1
# Copyright (C) 2006, 2007, 2008 Canonical Ltd
2
# Authors: Robert Collins <robert.collins@canonical.com>
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
19
"""Tests for the formatting and construction of errors."""
22
22
from bzrlib import (
87
87
"reason: reason for foo",
90
def test_inconsistent_delta_delta(self):
91
error = errors.InconsistentDeltaDelta([], 'reason')
93
"An inconsistent delta was supplied: []\nreason: reason",
96
90
def test_in_process_transport(self):
97
91
error = errors.InProcessTransport('fpp')
98
92
self.assertEqualDiff(
120
114
"read without data loss.",
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'.",
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))
129
126
def test_lock_active(self):
130
127
error = errors.LockActive("lock description")
248
245
"You will need to upgrade the branch to permit branch stacking.",
251
def test_unstackable_location(self):
252
error = errors.UnstackableLocationError('foo', 'bar')
253
self.assertEqualDiff("The branch 'foo' cannot be stacked on 'bar'.",
256
248
def test_unstackable_repository_format(self):
412
404
"""Test the formatting of MalformedBugIdentifier."""
413
405
error = errors.MalformedBugIdentifier('bogus', 'reason for bogosity')
414
406
self.assertEqual(
415
'Did not understand bug identifier bogus: reason for bogosity. '
416
'See "bzr help bugs" for more information on this feature.',
407
"Did not understand bug identifier bogus: reason for bogosity",
419
410
def test_unknown_bug_tracker_abbreviation(self):
543
534
except ZeroDivisionError:
544
535
exc_info = sys.exc_info()
545
err = errors.HookFailed('hook stage', 'hook name', exc_info, warn=False)
536
err = errors.HookFailed('hook stage', 'hook name', exc_info)
546
537
self.assertStartsWith(
547
538
str(err), 'Hook \'hook name\' during hook stage failed:\n')
548
539
self.assertEndsWith(
623
614
self.assertEqual(
624
615
'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)
659
618
class PassThroughError(errors.BzrError):
701
660
e = ErrorWithBadFormat(not_thing='x')
702
661
self.assertStartsWith(
703
662
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.",