~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
349
349
        self.assertEqual("The value 'foo' is not a valid value.",
350
350
            str(error))
351
351
 
352
 
    def test_bzrnewerror_is_deprecated(self):
353
 
        class DeprecatedError(errors.BzrNewError):
354
 
            pass
355
 
        self.callDeprecated(['BzrNewError was deprecated in bzr 0.13; '
356
 
             'please convert DeprecatedError to use BzrError instead'],
357
 
            DeprecatedError)
358
 
 
359
352
    def test_bzrerror_from_literal_string(self):
360
353
        # Some code constructs BzrError from a literal string, in which case
361
354
        # no further formatting is done.  (I'm not sure raising the base class
572
565
        err = errors.UnknownRules(['foo', 'bar'])
573
566
        self.assertEquals("Unknown rules detected: foo, bar.", str(err))
574
567
 
575
 
    def test_hook_failed(self):
576
 
        # Create an exc_info tuple by raising and catching an exception.
577
 
        try:
578
 
            1/0
579
 
        except ZeroDivisionError:
580
 
            err = errors.HookFailed('hook stage', 'hook name', sys.exc_info(),
581
 
                warn=False)
582
 
        # GZ 2010-11-08: Should not store exc_info in exception instances, but
583
 
        #                HookFailed is deprecated anyway and could maybe go.
584
 
        try:
585
 
            self.assertStartsWith(
586
 
                str(err), 'Hook \'hook name\' during hook stage failed:\n')
587
 
            self.assertEndsWith(
588
 
                str(err), 'integer division or modulo by zero')
589
 
        finally:
590
 
            del err
591
 
 
592
568
    def test_tip_change_rejected(self):
593
569
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
594
570
        self.assertEquals(
719
695
            'Please use `bzr unbind` to fix.')
720
696
        self.assertEqualDiff(msg, str(error))
721
697
 
 
698
    def test_retry_with_new_packs(self):
 
699
        fake_exc_info = ('{exc type}', '{exc value}', '{exc traceback}')
 
700
        error = errors.RetryWithNewPacks(
 
701
            '{context}', reload_occurred=False, exc_info=fake_exc_info)
 
702
        self.assertEqual(
 
703
            'Pack files have changed, reload and retry. context: '
 
704
            '{context} {exc value}', str(error))
 
705
 
722
706
 
723
707
class PassThroughError(errors.BzrError):
724
708
 
751
735
 
752
736
    def test_missing_format_string(self):
753
737
        e = ErrorWithNoFormat(param='randomvalue')
754
 
        s = self.callDeprecated(
755
 
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
756
 
                lambda x: str(x), e)
757
 
        ## s = str(e)
758
 
        self.assertEqual(s,
759
 
                "This class has a docstring but no format string.")
 
738
        self.assertStartsWith(str(e),
 
739
            "Unprintable exception ErrorWithNoFormat")
760
740
 
761
741
    def test_mismatched_format_args(self):
762
742
        # Even though ErrorWithBadFormat's format string does not match the