~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

  • Committer: Martin Packman
  • Date: 2011-12-05 14:21:55 UTC
  • mfrom: (6015.44.9 2.4)
  • mto: This revision was merged to the branch mainline in revision 6345.
  • Revision ID: martin.packman@canonical.com-20111205142155-t7s4lr5aau50dp8i
Merge 2.4 into bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from cStringIO import StringIO
22
22
import errno
 
23
import logging
23
24
import os
24
25
import re
25
26
import sys
346
347
        self.assertEqual(0, get_verbosity_level())
347
348
 
348
349
 
 
350
class TestLogging(TestCase):
 
351
    """Check logging functionality robustly records information"""
 
352
 
 
353
    def test_note(self):
 
354
        trace.note("Noted")
 
355
        self.assertEqual("    INFO  Noted\n", self.get_log())
 
356
 
 
357
    def test_warning(self):
 
358
        trace.warning("Warned")
 
359
        self.assertEqual(" WARNING  Warned\n", self.get_log())
 
360
 
 
361
    def test_log(self):
 
362
        logging.getLogger("bzr").error("Errored")
 
363
        self.assertEqual("   ERROR  Errored\n", self.get_log())
 
364
 
 
365
    def test_log_sub(self):
 
366
        logging.getLogger("bzr.test_log_sub").debug("Whispered")
 
367
        self.assertEqual("   DEBUG  Whispered\n", self.get_log())
 
368
 
 
369
    def test_log_unicode_msg(self):
 
370
        logging.getLogger("bzr").debug(u"\xa7")
 
371
        self.assertEqual(u"   DEBUG  \xa7\n", self.get_log())
 
372
 
 
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())
 
376
 
 
377
    def test_log_utf8_msg(self):
 
378
        logging.getLogger("bzr").debug("\xc2\xa7")
 
379
        self.assertEqual(u"   DEBUG  \xa7\n", self.get_log())
 
380
 
 
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())
 
384
 
 
385
    def test_log_bytes_msg(self):
 
386
        logging.getLogger("bzr").debug("\xa7")
 
387
        log = self.get_log()
 
388
        self.assertContainsString(log, "UnicodeDecodeError: ")
 
389
        self.assertContainsString(log,
 
390
            "Logging record unformattable: '\\xa7' % ()\n")
 
391
 
 
392
    def test_log_bytes_arg(self):
 
393
        logging.getLogger("bzr").debug("%s", "\xa7")
 
394
        log = self.get_log()
 
395
        self.assertContainsString(log, "UnicodeDecodeError: ")
 
396
        self.assertContainsString(log,
 
397
            "Logging record unformattable: '%s' % ('\\xa7',)\n")
 
398
 
 
399
    def test_log_mixed_strings(self):
 
400
        logging.getLogger("bzr").debug(u"%s", "\xa7")
 
401
        log = self.get_log()
 
402
        self.assertContainsString(log, "UnicodeDecodeError: ")
 
403
        self.assertContainsString(log,
 
404
            "Logging record unformattable: u'%s' % ('\\xa7',)\n")
 
405
 
 
406
    def test_log_repr_broken(self):
 
407
        class BadRepr(object):
 
408
            def __repr__(self):
 
409
                raise ValueError("Broken object")
 
410
        logging.getLogger("bzr").debug("%s", BadRepr())
 
411
        log = self.get_log()
 
412
        self.assertContainsRe(log, "ValueError: Broken object\n")
 
413
        self.assertContainsRe(log, "Logging record unformattable: '%s' % .*\n")
 
414
 
 
415
 
349
416
class TestBzrLog(TestCaseInTempDir):
350
417
 
351
418
    def test_log_rollover(self):