345
346
self.assertEqual(0, get_verbosity_level())
349
class TestLogging(TestCase):
350
"""Check logging functionality robustly records information"""
354
self.assertEqual(" INFO Noted\n", self.get_log())
356
def test_warning(self):
357
trace.warning("Warned")
358
self.assertEqual(" WARNING Warned\n", self.get_log())
361
logging.getLogger("bzr").error("Errored")
362
self.assertEqual(" ERROR Errored\n", self.get_log())
364
def test_log_sub(self):
365
logging.getLogger("bzr.test_log_sub").debug("Whispered")
366
self.assertEqual(" DEBUG Whispered\n", self.get_log())
368
def test_log_unicode_msg(self):
369
logging.getLogger("bzr").debug(u"\xa7")
370
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
372
def test_log_unicode_arg(self):
373
logging.getLogger("bzr").debug("%s", u"\xa7")
374
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
376
def test_log_utf8_msg(self):
377
logging.getLogger("bzr").debug("\xc2\xa7")
378
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
380
def test_log_utf8_arg(self):
381
logging.getLogger("bzr").debug("%s", "\xc2\xa7")
382
self.assertEqual(u" DEBUG \xa7\n", self.get_log())
384
def test_log_bytes_msg(self):
385
logging.getLogger("bzr").debug("\xa7")
387
self.assertContainsString(log, "UnicodeDecodeError: ")
388
self.assertContainsString(log,
389
"Logging record unformattable: '\\xa7' % ()\n")
391
def test_log_bytes_arg(self):
392
logging.getLogger("bzr").debug("%s", "\xa7")
394
self.assertContainsString(log, "UnicodeDecodeError: ")
395
self.assertContainsString(log,
396
"Logging record unformattable: '%s' % ('\\xa7',)\n")
398
def test_log_mixed_strings(self):
399
logging.getLogger("bzr").debug(u"%s", "\xa7")
401
self.assertContainsString(log, "UnicodeDecodeError: ")
402
self.assertContainsString(log,
403
"Logging record unformattable: u'%s' % ('\\xa7',)\n")
405
def test_log_repr_broken(self):
406
class BadRepr(object):
408
raise ValueError("Broken object")
409
logging.getLogger("bzr").debug("%s", BadRepr())
411
self.assertContainsRe(log, "ValueError: Broken object\n")
412
self.assertContainsRe(log, "Logging record unformattable: '%s' % .*\n")
348
415
class TestBzrLog(TestCaseInTempDir):
350
417
def test_log_rollover(self):