47
46
fmt_pattern = re.compile("%\(message\)[sir]")
48
subclasses_present = getattr(errors.BzrError, '__subclasses__', None)
49
if not subclasses_present:
50
raise TestSkipped('__subclasses__ attribute required for classes. '
51
'Requires Python 2.5 or later.')
52
47
for c in errors.BzrError.__subclasses__():
53
48
init = getattr(c, '__init__', None)
54
49
fmt = getattr(c, '_fmt', None)
62
57
'"errors.%s._fmt"' % c.__name__))
64
59
def test_bad_filename_encoding(self):
65
error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
67
"Filename 'bad/filen\\xe5me' is not valid in your current"
68
" filesystem encoding UTF-8",
60
error = errors.BadFilenameEncoding(b'bad/filen\xe5me', 'UTF-8')
61
self.assertContainsRe(
63
"^Filename b?'bad/filen\\\\xe5me' is not valid in your current"
64
" filesystem encoding UTF-8$")
71
66
def test_corrupt_dirstate(self):
72
67
error = errors.CorruptDirstate('path/to/dirstate', 'the reason why')
103
98
" its ancestry shows a ghost at {ghost_rev}",
106
def test_incompatibleAPI(self):
107
error = errors.IncompatibleAPI("module", (1, 2, 3), (4, 5, 6), (7, 8, 9))
101
def test_incompatibleVersion(self):
102
error = errors.IncompatibleVersion("module", [(4, 5, 6), (7, 8, 9)],
108
104
self.assertEqualDiff(
109
'The API for "module" is not compatible with "(1, 2, 3)". '
110
'It supports versions "(4, 5, 6)" to "(7, 8, 9)".',
105
'API module is not compatible; one of versions '
106
'[(4, 5, 6), (7, 8, 9)] is required, but current version is '
113
110
def test_inconsistent_delta(self):
199
196
self.assertEqualDiff(
200
197
"The medium 'a medium' is not connected.", str(error))
202
def test_no_public_branch(self):
203
b = self.make_branch('.')
204
error = errors.NoPublicBranch(b)
205
url = urlutils.unescape_for_display(b.base, 'ascii')
206
self.assertEqualDiff(
207
'There is no public branch set for "%s".' % url, str(error))
209
def test_no_repo(self):
210
dir = controldir.ControlDir.create(self.get_url())
211
error = errors.NoRepositoryPresent(dir)
212
self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
213
self.assertEqual(-1, str(error).find((dir.transport.base)))
215
199
def test_no_smart_medium(self):
216
200
error = errors.NoSmartMedium("a transport")
217
201
self.assertEqualDiff("The transport 'a transport' cannot tunnel the "
305
289
"The branch format someformat is already at the most "
306
290
"recent format.", str(error))
308
def test_corrupt_repository(self):
309
repo = self.make_repository('.')
310
error = errors.CorruptRepository(repo)
311
self.assertEqualDiff("An error has been detected in the repository %s.\n"
312
"Please run brz reconcile on this repository." %
313
repo.bzrdir.root_transport.base,
316
292
def test_read_error(self):
317
293
# a unicode path to check that %r is being used.
319
295
error = errors.ReadError(path)
320
self.assertEqualDiff("Error reading from u'a path'.", str(error))
296
self.assertContainsRe(str(error), "^Error reading from u?'a path'.$")
322
298
def test_bad_index_format_signature(self):
323
299
error = errors.BadIndexFormatSignature("foo", "bar")
445
421
'See "brz help bugs" for more information on this feature.',
448
def test_unknown_bug_tracker_abbreviation(self):
449
"""Test the formatting of UnknownBugTrackerAbbreviation."""
450
branch = self.make_branch('some_branch')
451
error = errors.UnknownBugTrackerAbbreviation('xxx', branch)
453
"Cannot find registered bug tracker called xxx on %s" % branch,
456
424
def test_unexpected_smart_server_response(self):
457
425
e = errors.UnexpectedSmartServerResponse(('not yes',))
458
426
self.assertEqual(
496
464
def test_duplicate_record_name_error(self):
497
465
"""Test the formatting of DuplicateRecordNameError."""
498
e = errors.DuplicateRecordNameError(u"n\xe5me".encode('utf-8'))
466
e = errors.DuplicateRecordNameError(b"n\xc3\xa5me")
499
467
self.assertEqual(
500
"Container has multiple records with the same name: n\xc3\xa5me",
468
u"Container has multiple records with the same name: n\xe5me",
503
471
def test_check_error(self):
504
# This has a member called 'message', which is problematic in
505
# python2.5 because that is a slot on the base Exception class
506
472
e = errors.BzrCheckError('example check failure')
507
473
self.assertEqual(
508
474
"Internal check failed: example check failure",
647
610
err = errors.NotBranchError('path')
648
611
self.assertEqual('Not a branch: "path".', str(err))
650
def test_not_branch_bzrdir_with_repo(self):
651
bzrdir = self.make_repository('repo').bzrdir
652
err = errors.NotBranchError('path', bzrdir=bzrdir)
654
'Not a branch: "path": location is a repository.', str(err))
656
def test_not_branch_bzrdir_without_repo(self):
657
bzrdir = self.make_bzrdir('bzrdir')
658
err = errors.NotBranchError('path', bzrdir=bzrdir)
659
self.assertEqual('Not a branch: "path".', str(err))
661
613
def test_not_branch_bzrdir_with_recursive_not_branch_error(self):
662
614
class FakeBzrDir(object):
663
615
def open_repository(self):
664
616
# str() on the NotBranchError will trigger a call to this,
665
617
# which in turn will another, identical NotBranchError.
666
raise errors.NotBranchError('path', bzrdir=FakeBzrDir())
667
err = errors.NotBranchError('path', bzrdir=FakeBzrDir())
668
self.assertEqual('Not a branch: "path".', str(err))
670
def test_not_branch_laziness(self):
671
real_bzrdir = self.make_bzrdir('path')
672
class FakeBzrDir(object):
675
def open_repository(self):
676
self.calls.append('open_repository')
677
raise errors.NoRepositoryPresent(real_bzrdir)
678
fake_bzrdir = FakeBzrDir()
679
err = errors.NotBranchError('path', bzrdir=fake_bzrdir)
680
self.assertEqual([], fake_bzrdir.calls)
682
self.assertEqual(['open_repository'], fake_bzrdir.calls)
683
# Stringifying twice doesn't try to open a repository twice.
685
self.assertEqual(['open_repository'], fake_bzrdir.calls)
618
raise errors.NotBranchError('path', controldir=FakeBzrDir())
619
err = errors.NotBranchError('path', controldir=FakeBzrDir())
620
self.assertEqual('Not a branch: "path": NotBranchError.', str(err))
687
622
def test_invalid_pattern(self):
688
623
error = errors.InvalidPattern('Bad pattern msg.')
764
699
self.assertEqual(
765
700
u"Failed to rename from to to: readonly file",
704
class TestErrorsUsingTransport(tests.TestCaseWithMemoryTransport):
705
"""Tests for errors that need to use a branch or repo."""
707
def test_no_public_branch(self):
708
b = self.make_branch('.')
709
error = errors.NoPublicBranch(b)
710
url = urlutils.unescape_for_display(b.base, 'ascii')
711
self.assertEqualDiff(
712
'There is no public branch set for "%s".' % url, str(error))
714
def test_no_repo(self):
715
dir = controldir.ControlDir.create(self.get_url())
716
error = errors.NoRepositoryPresent(dir)
717
self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
718
self.assertEqual(-1, str(error).find((dir.transport.base)))
720
def test_corrupt_repository(self):
721
repo = self.make_repository('.')
722
error = errors.CorruptRepository(repo)
723
self.assertEqualDiff("An error has been detected in the repository %s.\n"
724
"Please run brz reconcile on this repository." %
725
repo.controldir.root_transport.base,
728
def test_unknown_bug_tracker_abbreviation(self):
729
"""Test the formatting of UnknownBugTrackerAbbreviation."""
730
branch = self.make_branch('some_branch')
731
error = errors.UnknownBugTrackerAbbreviation('xxx', branch)
733
"Cannot find registered bug tracker called xxx on %s" % branch,
736
def test_not_branch_bzrdir_with_repo(self):
737
controldir = self.make_repository('repo').controldir
738
err = errors.NotBranchError('path', controldir=controldir)
740
'Not a branch: "path": location is a repository.', str(err))
742
def test_not_branch_bzrdir_without_repo(self):
743
controldir = self.make_controldir('bzrdir')
744
err = errors.NotBranchError('path', controldir=controldir)
745
self.assertEqual('Not a branch: "path".', str(err))
747
def test_not_branch_laziness(self):
748
real_bzrdir = self.make_controldir('path')
749
class FakeBzrDir(object):
752
def open_repository(self):
753
self.calls.append('open_repository')
754
raise errors.NoRepositoryPresent(real_bzrdir)
755
fake_bzrdir = FakeBzrDir()
756
err = errors.NotBranchError('path', controldir=fake_bzrdir)
757
self.assertEqual([], fake_bzrdir.calls)
759
self.assertEqual(['open_repository'], fake_bzrdir.calls)
760
# Stringifying twice doesn't try to open a repository twice.
762
self.assertEqual(['open_repository'], fake_bzrdir.calls)