~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: 2008-07-25 15:19:45 UTC
  • mfrom: (3577.1.3 tip-change-rejected-error)
  • Revision ID: pqm@pqm.ubuntu.com-20080725151945-kdaru30ix1m8k0h6
Add TipChangeRejected error so that pre_change_branch_tip hook
        functions can cleanly reject a change. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
"""Tests for the formatting and construction of errors."""
20
20
 
 
21
import sys
21
22
from bzrlib import (
22
23
    bzrdir,
23
24
    errors,
510
511
        err = errors.UnknownRules(['foo', 'bar'])
511
512
        self.assertEquals("Unknown rules detected: foo, bar.", str(err))
512
513
 
 
514
    def test_hook_failed(self):
 
515
        # Create an exc_info tuple by raising and catching an exception.
 
516
        try:
 
517
            1/0
 
518
        except ZeroDivisionError:
 
519
            exc_info = sys.exc_info()
 
520
        err = errors.HookFailed('hook stage', 'hook name', exc_info)
 
521
        self.assertStartsWith(
 
522
            str(err), 'Hook \'hook name\' during hook stage failed:\n')
 
523
        self.assertEndsWith(
 
524
            str(err), 'integer division or modulo by zero')
 
525
 
 
526
    def test_tip_change_rejected(self):
 
527
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
 
528
        self.assertEquals(
 
529
            u'Tip change rejected: Unicode message\N{INTERROBANG}',
 
530
            unicode(err))
 
531
        self.assertEquals(
 
532
            'Tip change rejected: Unicode message\xe2\x80\xbd',
 
533
            str(err))
 
534
 
513
535
 
514
536
class PassThroughError(errors.BzrError):
515
537