/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Robert Collins
  • Date: 2009-03-13 02:25:46 UTC
  • mfrom: (4133 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4183.
  • Revision ID: robertc@robertcollins.net-20090313022546-e7de5zsdkbay5okf
MergeĀ .dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
        error = errors.MediumNotConnected("a medium")
159
159
        self.assertEqualDiff(
160
160
            "The medium 'a medium' is not connected.", str(error))
161
 
 
 
161
 
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)))
174
 
        
 
174
 
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 "
256
256
 
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.",
262
262
                             str(error))
263
263
 
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.',
408
409
            str(error))
409
410
 
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",
463
464
            str(e))
464
 
        
 
465
 
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
561
562
        self.assertEquals(
562
563
            "Server sent an unexpected error: ('error', 'tuple')", str(err))
563
564
 
 
565
    def test_smart_message_handler_error(self):
 
566
        # Make an exc_info tuple.
 
567
        try:
 
568
            raise Exception("example error")
 
569
        except Exception:
 
570
            exc_info = sys.exc_info()
 
571
        err = errors.SmartMessageHandlerError(exc_info)
 
572
        self.assertStartsWith(
 
573
            str(err), "The message handler raised an exception:\n")
 
574
        self.assertEndsWith(str(err), "Exception: example error\n")
 
575
 
 
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"
 
579
                                   " working tree.")
 
580
 
 
581
    def test_no_such_view(self):
 
582
        err = errors.NoSuchView('foo')
 
583
        self.assertEquals("No such view: foo.", str(err))
 
584
 
 
585
    def test_views_not_supported(self):
 
586
        err = errors.ViewsNotSupported('atree')
 
587
        err_str = str(err)
 
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.")
 
591
 
 
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))
 
596
 
 
597
    def test_invalid_shelf_id(self):
 
598
        invalid_id = "foo"
 
599
        err = errors.InvalidShelfId(invalid_id)
 
600
        self.assertEqual('"foo" is not a valid shelf id, '
 
601
            'try a number instead.', str(err))
 
602
 
 
603
    def test_unresumable_write_group(self):
 
604
        repo = "dummy repo"
 
605
        wg_tokens = ['token']
 
606
        reason = "a reason"
 
607
        err = errors.UnresumableWriteGroup(repo, wg_tokens, reason)
 
608
        self.assertEqual(
 
609
            "Repository dummy repo cannot resume write group "
 
610
            "['token']: a reason", str(err))
 
611
 
 
612
    def test_unsuspendable_write_group(self):
 
613
        repo = "dummy repo"
 
614
        err = errors.UnsuspendableWriteGroup(repo)
 
615
        self.assertEqual(
 
616
            'Repository dummy repo cannot suspend a write group.', str(err))
 
617
 
564
618
 
565
619
class PassThroughError(errors.BzrError):
566
 
    
 
620
 
567
621
    _fmt = """Pass through %(foo)s and %(bar)s"""
568
622
 
569
623
    def __init__(self, foo, bar):
580
634
 
581
635
 
582
636
class TestErrorFormatting(TestCase):
583
 
    
 
637
 
584
638
    def test_always_str(self):
585
639
        e = PassThroughError(u'\xb5', 'bar')
586
640
        self.assertIsInstance(e.__str__(), str)
597
651
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
598
652
                lambda x: str(x), e)
599
653
        ## s = str(e)
600
 
        self.assertEqual(s, 
 
654
        self.assertEqual(s,
601
655
                "This class has a docstring but no format string.")
602
656
 
603
657
    def test_mismatched_format_args(self):