~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-06-05 04:05:05 UTC
  • mfrom: (3473.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080605040505-i9kqxg2fps2qjdi0
Add the 'alias' command (Tim Penhey)

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
22
21
from bzrlib import (
23
22
    bzrdir,
24
23
    errors,
31
30
 
32
31
class TestErrors(TestCaseWithTransport):
33
32
 
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
 
 
41
33
    def test_corrupt_dirstate(self):
42
34
        error = errors.CorruptDirstate('path/to/dirstate', 'the reason why')
43
35
        self.assertEqualDiff(
45
37
            "Error: the reason why",
46
38
            str(error))
47
39
 
48
 
    def test_dirstate_corrupt(self):
49
 
        error = errors.DirstateCorrupt('.bzr/checkout/dirstate',
50
 
                                       'trailing garbage: "x"')
51
 
        self.assertEqualDiff("The dirstate file (.bzr/checkout/dirstate)"
52
 
            " appears to be corrupt: trailing garbage: \"x\"",
53
 
            str(error))
54
 
 
55
40
    def test_disabled_method(self):
56
41
        error = errors.DisabledMethod("class name")
57
42
        self.assertEqualDiff(
391
376
            host='ahost', port=444, msg='Unable to connect to ssh host',
392
377
            orig_error='my_error')
393
378
 
394
 
    def test_target_not_branch(self):
395
 
        """Test the formatting of TargetNotBranch."""
396
 
        error = errors.TargetNotBranch('foo')
397
 
        self.assertEqual(
398
 
            "Your branch does not have all of the revisions required in "
399
 
            "order to merge this merge directive and the target "
400
 
            "location specified in the merge directive is not a branch: "
401
 
            "foo.", str(error))
402
 
 
403
379
    def test_malformed_bug_identifier(self):
404
380
        """Test the formatting of MalformedBugIdentifier."""
405
381
        error = errors.MalformedBugIdentifier('bogus', 'reason for bogosity')
523
499
        err = errors.UnknownFormatError('bar', kind='foo')
524
500
        self.assertEquals("Unknown foo format: 'bar'", str(err))
525
501
 
526
 
    def test_unknown_rules(self):
527
 
        err = errors.UnknownRules(['foo', 'bar'])
528
 
        self.assertEquals("Unknown rules detected: foo, bar.", str(err))
529
 
 
530
 
    def test_hook_failed(self):
531
 
        # Create an exc_info tuple by raising and catching an exception.
532
 
        try:
533
 
            1/0
534
 
        except ZeroDivisionError:
535
 
            exc_info = sys.exc_info()
536
 
        err = errors.HookFailed('hook stage', 'hook name', exc_info)
537
 
        self.assertStartsWith(
538
 
            str(err), 'Hook \'hook name\' during hook stage failed:\n')
539
 
        self.assertEndsWith(
540
 
            str(err), 'integer division or modulo by zero')
541
 
 
542
 
    def test_tip_change_rejected(self):
543
 
        err = errors.TipChangeRejected(u'Unicode message\N{INTERROBANG}')
544
 
        self.assertEquals(
545
 
            u'Tip change rejected: Unicode message\N{INTERROBANG}',
546
 
            unicode(err))
547
 
        self.assertEquals(
548
 
            'Tip change rejected: Unicode message\xe2\x80\xbd',
549
 
            str(err))
550
 
 
551
 
    def test_error_from_smart_server(self):
552
 
        error_tuple = ('error', 'tuple')
553
 
        err = errors.ErrorFromSmartServer(error_tuple)
554
 
        self.assertEquals(
555
 
            "Error received from smart server: ('error', 'tuple')", str(err))
556
 
 
557
 
    def test_untranslateable_error_from_smart_server(self):
558
 
        error_tuple = ('error', 'tuple')
559
 
        orig_err = errors.ErrorFromSmartServer(error_tuple)
560
 
        err = errors.UnknownErrorFromSmartServer(orig_err)
561
 
        self.assertEquals(
562
 
            "Server sent an unexpected error: ('error', 'tuple')", str(err))
563
 
 
564
502
 
565
503
class PassThroughError(errors.BzrError):
566
504