~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

(jelmer) Reduce the number of connections made during "bzr branch
 --stacked". (Jelmer Vernooij)

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
 
352
359
    def test_bzrerror_from_literal_string(self):
353
360
        # Some code constructs BzrError from a literal string, in which case
354
361
        # no further formatting is done.  (I'm not sure raising the base class
565
572
        err = errors.UnknownRules(['foo', 'bar'])
566
573
        self.assertEquals("Unknown rules detected: foo, bar.", str(err))
567
574
 
 
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
 
568
592
    def test_tip_change_rejected(self):
569
593
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
570
594
        self.assertEquals(
735
759
 
736
760
    def test_missing_format_string(self):
737
761
        e = ErrorWithNoFormat(param='randomvalue')
738
 
        self.assertStartsWith(str(e),
739
 
            "Unprintable exception ErrorWithNoFormat")
 
762
        s = self.callDeprecated(
 
763
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
 
764
                lambda x: str(x), e)
 
765
        ## s = str(e)
 
766
        self.assertEqual(s,
 
767
                "This class has a docstring but no format string.")
740
768
 
741
769
    def test_mismatched_format_args(self):
742
770
        # Even though ErrorWithBadFormat's format string does not match the