215
216
# have to do a replaceent here as well.
216
217
self.assertContainsRe(log, "ascii argument: \xb5".decode('utf8',
220
def test_show_error(self):
222
show_error(u'error2 \xb5 blah')
223
show_error('arg: %s', 'blah')
224
show_error('arg2: %(key)s', {'key':'stuff'})
226
raise Exception("oops")
228
show_error('kwarg', exc_info=True)
230
self.assertContainsRe(log, 'error1')
231
self.assertContainsRe(log, u'error2 \xb5 blah')
232
self.assertContainsRe(log, 'arg: blah')
233
self.assertContainsRe(log, 'arg2: stuff')
234
self.assertContainsRe(log, 'kwarg')
235
self.assertContainsRe(log, 'Traceback \\(most recent call last\\):')
236
self.assertContainsRe(log, 'File ".*test_trace.py", line .*, in test_show_error')
237
self.assertContainsRe(log, 'raise Exception\\("oops"\\)')
238
self.assertContainsRe(log, 'Exception: oops')
219
240
def test_push_log_file(self):
220
241
"""Can push and pop log file, and this catches mutter messages.
253
274
# If _open_bzr_log cannot open the file, then we should write the
254
275
# warning to stderr. Since this is normally happening before logging is
256
self.addCleanup(setattr, sys, 'stderr', sys.stderr)
257
self.addCleanup(setattr, trace, '_bzr_log_filename',
258
trace._bzr_log_filename)
259
sys.stderr = StringIO()
277
self.overrideAttr(sys, 'stderr', StringIO())
260
278
# Set the log file to something that cannot exist
279
# FIXME: A bit dangerous: we are not in an isolated dir here -- vilajam
261
281
os.environ['BZR_LOG'] = os.getcwd() + '/no-dir/bzr.log'
282
self.overrideAttr(trace, '_bzr_log_filename')
262
283
logf = trace._open_bzr_log()
263
284
self.assertIs(None, logf)
264
285
self.assertContainsRe(sys.stderr.getvalue(),
265
286
'failed to open trace file: .*/no-dir/bzr.log')
267
289
class TestVerbosityLevel(TestCase):
269
291
def test_verbosity_level(self):