~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_errors.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        error = errors.NoRepositoryPresent(dir)
32
32
        self.assertNotEqual(-1, str(error).find((dir.transport.clone('..').base)))
33
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))
34
40
 
35
41
    def test_up_to_date(self):
36
42
        error = errors.UpToDateFormat(bzrdir.BzrDirFormat4())
55
61
        errors.BzrNewError.__init__(self, foo=foo, bar=bar)
56
62
 
57
63
 
 
64
class ErrorWithBadFormat(errors.BzrNewError):
 
65
    """One format specifier: %(thing)s"""
 
66
 
 
67
 
58
68
class TestErrorFormatting(TestCase):
59
69
    
60
70
    def test_always_str(self):
66
76
        # returned from e.__str__(), and it has non ascii characters
67
77
        s = str(e)
68
78
        self.assertEqual('Pass through \xc2\xb5 and bar', s)
 
79
 
 
80
    def test_mismatched_format_args(self):
 
81
        # Even though ErrorWithBadFormat's format string does not match the
 
82
        # arguments we constructing it with, we can still stringify an instance
 
83
        # of this exception. The resulting string will say its unprintable.
 
84
        e = ErrorWithBadFormat(not_thing='x')
 
85
        self.assertStartsWith(
 
86
            str(e), 'Unprintable exception ErrorWithBadFormat(')
 
87