29
29
from bzrlib.tests import TestCaseInTempDir, TestCase
30
from bzrlib.trace import mutter, report_exception
30
from bzrlib.trace import mutter, mutter_callsite, report_exception
33
33
def _format_exception():
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')
116
140
def test_mutter_never_fails(self):
117
141
# Even if the decode/encode stage fails, mutter should not
118
142
# raise an exception
123
147
self.assertContainsRe(log, 'Writing a greek mu')
124
148
self.assertContainsRe(log, "But fails in an ascii string")
125
149
self.assertContainsRe(log, u"ascii argument: \xb5")