本文整理汇总了Python中testfixtures.LogCapture.addFilter方法的典型用法代码示例。如果您正苦于以下问题:Python LogCapture.addFilter方法的具体用法?Python LogCapture.addFilter怎么用?Python LogCapture.addFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testfixtures.LogCapture
的用法示例。
在下文中一共展示了LogCapture.addFilter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TopLevelFormatterTest
# 需要导入模块: from testfixtures import LogCapture [as 别名]
# 或者: from testfixtures.LogCapture import addFilter [as 别名]
class TopLevelFormatterTest(unittest.TestCase):
def setUp(self):
self.handler = LogCapture()
self.handler.addFilter(TopLevelFormatter(['test']))
def test_top_level_logger(self):
logger = logging.getLogger('test')
with self.handler as l:
logger.warning('test log msg')
l.check(('test', 'WARNING', 'test log msg'))
def test_children_logger(self):
logger = logging.getLogger('test.test1')
with self.handler as l:
logger.warning('test log msg')
l.check(('test', 'WARNING', 'test log msg'))
def test_overlapping_name_logger(self):
logger = logging.getLogger('test2')
with self.handler as l:
logger.warning('test log msg')
l.check(('test2', 'WARNING', 'test log msg'))
def test_different_name_logger(self):
logger = logging.getLogger('different')
with self.handler as l:
logger.warning('test log msg')
l.check(('different', 'WARNING', 'test log msg'))
示例2: TestHTMLFilter
# 需要导入模块: from testfixtures import LogCapture [as 别名]
# 或者: from testfixtures.LogCapture import addFilter [as 别名]
class TestHTMLFilter(TestCase):
def setUp(self):
self.log = LogCapture()
self.logger = getLogger()
self.log.addFilter(HTMLFilter())
def tearDown(self):
self.log.uninstall()
def test_plain_string(self):
self.logger.info('foo')
self.log.check(('root', 'INFO', 'foo'),)
def test_html_string(self):
self.logger.info('<foo &bar>')
self.log.check(('root', 'INFO', '<foo &bar>'),)
def test_with_params_string(self):
self.logger.info('%s', 'foo')
self.log.check(('root', 'INFO', 'foo'),)
def test_plain_unicode(self):
self.logger.info(u"accentu\u00E9")
self.log.check(('root', 'INFO', u'accentu\xe9'),)
def test_html_unicode(self):
self.logger.info(u"<u\u00E9 &bar>")
self.log.check(('root', 'INFO', u'<u\xe9 &bar>'),)
def test_with_params_unicode(self):
self.logger.info(u"\u00E9%s", u"accentu\u00E9")
self.log.check(('root', 'INFO', u'\xe9accentu\xe9'),)
def test_some_object(self):
class AnObject(object):
def __repr__(self):
return 'obj'
__str__ = __repr__
self.logger.info(AnObject())
self.log.check(('root', 'INFO', 'obj'),)