~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Patch Queue Manager
  • Date: 2015-12-17 18:39:00 UTC
  • mfrom: (6606.1.2 fix-float)
  • Revision ID: pqm@pqm.ubuntu.com-20151217183900-0719du2uv1kwu3lc
(vila) Inline testtools private method to fix an issue in xenial (the
 private implementation has changed in an backward incompatible way).
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import sys
23
23
 
24
24
from bzrlib import (
25
 
    bzrdir,
 
25
    controldir,
26
26
    errors,
27
27
    osutils,
28
28
    urlutils,
207
207
            'There is no public branch set for "%s".' % url, str(error))
208
208
 
209
209
    def test_no_repo(self):
210
 
        dir = bzrdir.BzrDir.create(self.get_url())
 
210
        dir = controldir.ControlDir.create(self.get_url())
211
211
        error = errors.NoRepositoryPresent(dir)
212
212
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
213
213
        self.assertEqual(-1, str(error).find((dir.transport.base)))
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