158
158
error = errors.MediumNotConnected("a medium")
159
159
self.assertEqualDiff(
160
160
"The medium 'a medium' is not connected.", str(error))
162
162
def test_no_public_branch(self):
163
163
b = self.make_branch('.')
164
164
error = errors.NoPublicBranch(b)
171
171
error = errors.NoRepositoryPresent(dir)
172
172
self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
173
173
self.assertEqual(-1, str(error).find((dir.transport.base)))
175
175
def test_no_smart_medium(self):
176
176
error = errors.NoSmartMedium("a transport")
177
177
self.assertEqualDiff("The transport 'a transport' cannot tunnel the "
257
257
def test_up_to_date(self):
258
258
error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
259
self.assertEqualDiff("The branch format Bazaar-NG branch, "
260
"format 0.0.4 is already at the most "
259
self.assertEqualDiff("The branch format All-in-one "
260
"format 4 is already at the most "
261
261
"recent format.",
404
404
"""Test the formatting of MalformedBugIdentifier."""
405
405
error = errors.MalformedBugIdentifier('bogus', 'reason for bogosity')
406
406
self.assertEqual(
407
"Did not understand bug identifier bogus: reason for bogosity",
407
'Did not understand bug identifier bogus: reason for bogosity. '
408
'See "bzr help bugs" for more information on this feature.',
410
411
def test_unknown_bug_tracker_abbreviation(self):
461
462
self.assertEqual(
462
463
"Container has multiple records with the same name: n\xc3\xa5me",
465
466
def test_check_error(self):
466
467
# This has a member called 'message', which is problematic in
467
468
# python2.5 because that is a slot on the base Exception class
560
561
err = errors.UnknownErrorFromSmartServer(orig_err)
561
562
self.assertEquals(
562
563
"Server sent an unexpected error: ('error', 'tuple')", str(err))
564
565
def test_smart_message_handler_error(self):
565
566
# Make an exc_info tuple.
572
573
str(err), "The message handler raised an exception:\n")
573
574
self.assertEndsWith(str(err), "Exception: example error\n")
576
def test_must_have_working_tree(self):
577
err = errors.MustHaveWorkingTree('foo', 'bar')
578
self.assertEqual(str(err), "Branching 'bar'(foo) must create a"
581
def test_no_such_view(self):
582
err = errors.NoSuchView('foo')
583
self.assertEquals("No such view: foo.", str(err))
585
def test_views_not_supported(self):
586
err = errors.ViewsNotSupported('atree')
588
self.assertStartsWith(err_str, "Views are not supported by ")
589
self.assertEndsWith(err_str, "; use 'bzr upgrade' to change your "
590
"tree to a later format.")
592
def test_file_outside_view(self):
593
err = errors.FileOutsideView('baz', ['foo', 'bar'])
594
self.assertEquals('Specified file "baz" is outside the current view: '
595
'foo, bar', str(err))
597
def test_invalid_shelf_id(self):
599
err = errors.InvalidShelfId(invalid_id)
600
self.assertEqual('"foo" is not a valid shelf id, '
601
'try a number instead.', str(err))
603
def test_unresumable_write_group(self):
605
wg_tokens = ['token']
607
err = errors.UnresumableWriteGroup(repo, wg_tokens, reason)
609
"Repository dummy repo cannot resume write group "
610
"['token']: a reason", str(err))
612
def test_unsuspendable_write_group(self):
614
err = errors.UnsuspendableWriteGroup(repo)
616
'Repository dummy repo cannot suspend a write group.', str(err))
576
619
class PassThroughError(errors.BzrError):
578
621
_fmt = """Pass through %(foo)s and %(bar)s"""
580
623
def __init__(self, foo, bar):
593
636
class TestErrorFormatting(TestCase):
595
638
def test_always_str(self):
596
639
e = PassThroughError(u'\xb5', 'bar')
597
640
self.assertIsInstance(e.__str__(), str)