~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Vincent Ladeuil
  • Date: 2016-01-21 11:42:23 UTC
  • mto: This revision was merged to the branch mainline in revision 6610.
  • Revision ID: v.ladeuil+lp@free.fr-20160121114223-ngcvndi02ydiqs5z
Allow hyphens in option names to unbreak compatibility.

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)))
300
300
            str(error))
301
301
 
302
302
    def test_up_to_date(self):
303
 
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
304
 
        self.assertEqualDiff("The branch format All-in-one "
305
 
                             "format 4 is already at the most "
306
 
                             "recent format.",
307
 
                             str(error))
 
303
        error = errors.UpToDateFormat("someformat")
 
304
        self.assertEqualDiff(
 
305
            "The branch format someformat is already at the most "
 
306
            "recent format.", str(error))
308
307
 
309
308
    def test_corrupt_repository(self):
310
309
        repo = self.make_repository('.')
350
349
        self.assertEqual("The value 'foo' is not a valid value.",
351
350
            str(error))
352
351
 
353
 
    def test_bzrnewerror_is_deprecated(self):
354
 
        class DeprecatedError(errors.BzrNewError):
355
 
            pass
356
 
        self.callDeprecated(['BzrNewError was deprecated in bzr 0.13; '
357
 
             'please convert DeprecatedError to use BzrError instead'],
358
 
            DeprecatedError)
359
 
 
360
352
    def test_bzrerror_from_literal_string(self):
361
353
        # Some code constructs BzrError from a literal string, in which case
362
354
        # no further formatting is done.  (I'm not sure raising the base class
573
565
        err = errors.UnknownRules(['foo', 'bar'])
574
566
        self.assertEquals("Unknown rules detected: foo, bar.", str(err))
575
567
 
576
 
    def test_hook_failed(self):
577
 
        # Create an exc_info tuple by raising and catching an exception.
578
 
        try:
579
 
            1/0
580
 
        except ZeroDivisionError:
581
 
            exc_info = sys.exc_info()
582
 
        err = errors.HookFailed('hook stage', 'hook name', exc_info, warn=False)
583
 
        self.assertStartsWith(
584
 
            str(err), 'Hook \'hook name\' during hook stage failed:\n')
585
 
        self.assertEndsWith(
586
 
            str(err), 'integer division or modulo by zero')
587
 
 
588
568
    def test_tip_change_rejected(self):
589
569
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
590
570
        self.assertEquals(
612
592
        try:
613
593
            raise Exception("example error")
614
594
        except Exception:
615
 
            exc_info = sys.exc_info()
616
 
        err = errors.SmartMessageHandlerError(exc_info)
617
 
        self.assertStartsWith(
618
 
            str(err), "The message handler raised an exception:\n")
619
 
        self.assertEndsWith(str(err), "Exception: example error\n")
 
595
            err = errors.SmartMessageHandlerError(sys.exc_info())
 
596
        # GZ 2010-11-08: Should not store exc_info in exception instances.
 
597
        try:
 
598
            self.assertStartsWith(
 
599
                str(err), "The message handler raised an exception:\n")
 
600
            self.assertEndsWith(str(err), "Exception: example error\n")
 
601
        finally:
 
602
            del err
620
603
 
621
604
    def test_must_have_working_tree(self):
622
605
        err = errors.MustHaveWorkingTree('foo', 'bar')
712
695
            'Please use `bzr unbind` to fix.')
713
696
        self.assertEqualDiff(msg, str(error))
714
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
 
715
706
 
716
707
class PassThroughError(errors.BzrError):
717
708
 
744
735
 
745
736
    def test_missing_format_string(self):
746
737
        e = ErrorWithNoFormat(param='randomvalue')
747
 
        s = self.callDeprecated(
748
 
                ['ErrorWithNoFormat uses its docstring as a format, it should use _fmt instead'],
749
 
                lambda x: str(x), e)
750
 
        ## s = str(e)
751
 
        self.assertEqual(s,
752
 
                "This class has a docstring but no format string.")
 
738
        self.assertStartsWith(str(e),
 
739
            "Unprintable exception ErrorWithNoFormat")
753
740
 
754
741
    def test_mismatched_format_args(self):
755
742
        # Even though ErrorWithBadFormat's format string does not match the