29
29
from bzrlib.tests import TestCaseInTempDir, TestCase
30
from bzrlib.trace import mutter, mutter_callsite, report_exception
30
from bzrlib.trace import mutter, report_exception
33
33
def _format_exception():
84
84
msg = _format_exception()
85
85
self.assertTrue(len(msg) > 0)
86
self.assertEqualDiff(msg, 'bzr: ERROR: Not a branch: \"wibble\".\n')
86
self.assertEqualDiff(msg, 'bzr: ERROR: Not a branch: wibble\n')
88
88
def test_trace_unicode(self):
89
89
"""Write Unicode to trace log"""
114
114
self.fail("expected error not raised")
116
def test_mutter_callsite_1(self):
117
"""mutter_callsite can capture 1 level of stack frame."""
118
mutter_callsite(1, "foo %s", "a string")
119
log = self._get_log(keep_log_file=True)
120
# begin with the message
121
self.assertStartsWith(log, 'foo a string\nCalled from:\n')
122
# should show two frame: this frame and the one above
123
self.assertContainsRe(log,
124
'test_trace\.py", line \d+, in test_mutter_callsite_1\n')
125
# this frame should be the final one
126
self.assertEndsWith(log, ' "a string")\n')
128
def test_mutter_callsite_2(self):
129
"""mutter_callsite can capture 2 levels of stack frame."""
130
mutter_callsite(2, "foo %s", "a string")
131
log = self._get_log(keep_log_file=True)
132
# begin with the message
133
self.assertStartsWith(log, 'foo a string\nCalled from:\n')
134
# should show two frame: this frame and the one above
135
self.assertContainsRe(log,
136
'test_trace.py", line \d+, in test_mutter_callsite_2\n')
137
# this frame should be the final one
138
self.assertEndsWith(log, ' "a string")\n')
140
116
def test_mutter_never_fails(self):
141
117
# Even if the decode/encode stage fails, mutter should not
142
118
# raise an exception
147
123
self.assertContainsRe(log, 'Writing a greek mu')
148
124
self.assertContainsRe(log, "But fails in an ascii string")
149
125
self.assertContainsRe(log, u"ascii argument: \xb5")