/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

Add a new method ``Tree.revision_tree`` which allows access to cached
trees for arbitrary revisions. This allows the in development dirstate
tree format to provide access to the callers to cached copies of 
inventory data which are cheaper to access than inventories from the
repository. (Robert Collins, Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""Tests for the formatting and construction of errors."""
19
19
 
20
 
import bzrlib.bzrdir as bzrdir
21
 
import bzrlib.errors as errors
22
 
from bzrlib.tests import TestCaseWithTransport
 
20
from bzrlib import (
 
21
    bzrdir,
 
22
    errors,
 
23
    )
 
24
from bzrlib.tests import TestCase, TestCaseWithTransport
23
25
 
24
26
 
25
27
class TestErrors(TestCaseWithTransport):
27
29
    def test_no_repo(self):
28
30
        dir = bzrdir.BzrDir.create(self.get_url())
29
31
        error = errors.NoRepositoryPresent(dir)
30
 
        self.assertNotEqual(-1, str(error).find(repr(dir.transport.clone('..').base)))
31
 
        self.assertEqual(-1, str(error).find(repr(dir.transport.base)))
 
32
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
 
33
        self.assertEqual(-1, str(error).find((dir.transport.base)))
 
34
        
 
35
    def test_no_such_id(self):
 
36
        error = errors.NoSuchId("atree", "anid")
 
37
        self.assertEqualDiff("The file id anid is not present in the tree "
 
38
            "atree.",
 
39
            str(error))
 
40
 
 
41
    def test_no_such_revision_in_tree(self):
 
42
        error = errors.NoSuchRevisionInTree("atree", "anid")
 
43
        self.assertEqualDiff("The revision id anid is not present in the tree "
 
44
            "atree.",
 
45
            str(error))
 
46
        self.assertIsInstance(error, errors.NoSuchRevision)
32
47
 
33
48
    def test_up_to_date(self):
34
49
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
44
59
                             "Please run bzr reconcile on this repository." %
45
60
                             repo.bzrdir.root_transport.base,
46
61
                             str(error))
 
62
 
 
63
 
 
64
class PassThroughError(errors.BzrNewError):
 
65
    """Pass through %(foo)s and %(bar)s"""
 
66
 
 
67
    def __init__(self, foo, bar):
 
68
        errors.BzrNewError.__init__(self, foo=foo, bar=bar)
 
69
 
 
70
 
 
71
class TestErrorFormatting(TestCase):
 
72
    
 
73
    def test_always_str(self):
 
74
        e = PassThroughError(u'\xb5', 'bar')
 
75
        self.assertIsInstance(e.__str__(), str)
 
76
        # In Python str(foo) *must* return a real byte string
 
77
        # not a Unicode string. The following line would raise a
 
78
        # Unicode error, because it tries to call str() on the string
 
79
        # returned from e.__str__(), and it has non ascii characters
 
80
        s = str(e)
 
81
        self.assertEqual('Pass through \xc2\xb5 and bar', s)