~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

  • Committer: Andrew Bennetts
  • Date: 2008-07-28 06:53:44 UTC
  • mfrom: (3581 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3583.
  • Revision ID: andrew.bennetts@canonical.com-20080728065344-ocndjoycs903q6fz
Merge bzr.dev.

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,
30
31
 
31
32
class TestErrors(TestCaseWithTransport):
32
33
 
 
34
    def test_bad_filename_encoding(self):
 
35
        error = errors.BadFilenameEncoding('bad/filen\xe5me', 'UTF-8')
 
36
        self.assertEqualDiff(
 
37
            "Filename 'bad/filen\\xe5me' is not valid in your current"
 
38
            " filesystem encoding UTF-8",
 
39
            str(error))
 
40
 
33
41
    def test_corrupt_dirstate(self):
34
42
        error = errors.CorruptDirstate('path/to/dirstate', 'the reason why')
35
43
        self.assertEqualDiff(
499
507
        err = errors.UnknownFormatError('bar', kind='foo')
500
508
        self.assertEquals("Unknown foo format: 'bar'", str(err))
501
509
 
 
510
    def test_unknown_rules(self):
 
511
        err = errors.UnknownRules(['foo', 'bar'])
 
512
        self.assertEquals("Unknown rules detected: foo, bar.", str(err))
 
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
 
502
535
 
503
536
class PassThroughError(errors.BzrError):
504
537