~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

Merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
import sys
24
24
 
25
 
from bzrlib.selftest import TestCaseInTempDir, TestCase
26
 
from bzrlib.trace import format_exception_short
27
 
from bzrlib.errors import NotBranchError
 
25
from bzrlib.tests import TestCaseInTempDir, TestCase
 
26
from bzrlib.trace import format_exception_short, mutter
 
27
from bzrlib.errors import NotBranchError, BzrError, BzrNewError
28
28
 
29
29
class TestTrace(TestCase):
30
30
    def test_format_sys_exception(self):
37
37
        self.assertEqualDiff(error_lines[0], 
38
38
                'exceptions.NotImplementedError: time travel')
39
39
        self.assertContainsRe(error_lines[1], 
40
 
                r'^  at .*testtrace\.py line \d+$')  
 
40
                r'^  at .*trace\.py line \d+$')  
41
41
        self.assertContainsRe(error_lines[2], 
42
42
                r'^  in test_format_sys_exception$')
43
43
 
49
49
            pass
50
50
        msg = format_exception_short(sys.exc_info())
51
51
        self.assertEqualDiff(msg, 'Not a branch: wibble')
 
52
 
 
53
    def test_format_old_exception(self):
 
54
        # format a class that doesn't descend from BzrNewError; 
 
55
        # remove this test when everything is unified there
 
56
        self.assertFalse(issubclass(BzrError, BzrNewError))
 
57
        try:
 
58
            raise BzrError('some old error')
 
59
        except BzrError:
 
60
            pass
 
61
        msg = format_exception_short(sys.exc_info())
 
62
        self.assertEqualDiff(msg, 'some old error')
 
63
 
 
64
    def test_trace_unicode(self):
 
65
        """Write Unicode to trace log"""
 
66
        self.log(u'the unicode character for benzene is \N{BENZENE RING}')
 
67
        self.assertContainsRe('the unicode character',
 
68
                self._get_log())