~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import sys
23
23
 
24
24
from bzrlib import (
25
 
    controldir,
 
25
    bzrdir,
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 = controldir.ControlDir.create(self.get_url())
 
210
        dir = bzrdir.BzrDir.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
 
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(
695
719
            'Please use `bzr unbind` to fix.')
696
720
        self.assertEqualDiff(msg, str(error))
697
721
 
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
 
 
706
722
 
707
723
class PassThroughError(errors.BzrError):
708
724
 
735
751
 
736
752
    def test_missing_format_string(self):
737
753
        e = ErrorWithNoFormat(param='randomvalue')
738
 
        self.assertStartsWith(str(e),
739
 
            "Unprintable exception ErrorWithNoFormat")
 
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.")
740
760
 
741
761
    def test_mismatched_format_args(self):
742
762
        # Even though ErrorWithBadFormat's format string does not match the