114
113
msg = _format_exception()
115
114
# Even though Windows and Linux differ for 'os.rmdir', they both give
116
115
# 'No such file' for open()
117
# However it now gets translated so we can not test for a specific message
118
116
self.assertContainsRe(msg,
119
r'^bzr: ERROR: \[Errno .*\] .*nosuchfile')
117
r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
121
119
def test_format_pywintypes_error(self):
122
120
self.requireFeature(features.pywintypes)
347
345
self.assertEqual(0, get_verbosity_level())
350
class TestLogging(TestCase):
351
"""Check logging functionality robustly records information"""
355
self.assertEqual(" INFO Noted\n", self.get_log())
357
def test_warning(self):
358
trace.warning("Warned")
359
self.assertEqual(" WARNING Warned\n", self.get_log())
362
logging.getLogger("bzr").error("Errored")
363
self.assertEqual(" ERROR Errored\n", self.get_log())
365
def test_log_sub(self):
366
logging.getLogger("bzr.test_log_sub").debug("Whispered")
367
self.assertEqual(" DEBUG Whispered\n", self.get_log())
369
def test_log_unicode_msg(self):
370
logging.getLogger("bzr").debug(u"\xa7")
371
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
373
def test_log_unicode_arg(self):
374
logging.getLogger("bzr").debug("%s", u"\xa7")
375
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
377
def test_log_utf8_msg(self):
378
logging.getLogger("bzr").debug("\xc2\xa7")
379
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
381
def test_log_utf8_arg(self):
382
logging.getLogger("bzr").debug("%s", "\xc2\xa7")
383
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
385
def test_log_bytes_msg(self):
386
logging.getLogger("bzr").debug("\xa7")
388
self.assertContainsString(log, "UnicodeDecodeError: ")
389
self.assertContainsString(log,
390
"Logging record unformattable: '\\xa7' % ()\n")
392
def test_log_bytes_arg(self):
393
logging.getLogger("bzr").debug("%s", "\xa7")
395
self.assertContainsString(log, "UnicodeDecodeError: ")
396
self.assertContainsString(log,
397
"Logging record unformattable: '%s' % ('\\xa7',)\n")
399
def test_log_mixed_strings(self):
400
logging.getLogger("bzr").debug(u"%s", "\xa7")
402
self.assertContainsString(log, "UnicodeDecodeError: ")
403
self.assertContainsString(log,
404
"Logging record unformattable: u'%s' % ('\\xa7',)\n")
406
def test_log_repr_broken(self):
407
class BadRepr(object):
409
raise ValueError("Broken object")
410
logging.getLogger("bzr").debug("%s", BadRepr())
412
self.assertContainsRe(log, "ValueError: Broken object\n")
413
self.assertContainsRe(log, "Logging record unformattable: '%s' % .*\n")
416
348
class TestBzrLog(TestCaseInTempDir):
418
350
def test_log_rollover(self):