• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python logcapture.LogCapture类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nose.plugins.logcapture.LogCapture的典型用法代码示例。如果您正苦于以下问题:Python LogCapture类的具体用法?Python LogCapture怎么用?Python LogCapture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了LogCapture类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_unicode_messages_handled

    def test_unicode_messages_handled(self):
        msg = u'Ivan Krsti\u0107'
        c = LogCapture()
        parser = OptionParser()
        c.addOptions(parser, {})
        options, args = parser.parse_args([])
        c.configure(options, Config())
        c.start()
        log = logging.getLogger("foobar.something")
        log.debug(msg)
        log.debug("ordinary string log")
        c.end()

        class Dummy:
            pass
        test = Dummy() 
        try:
            raise Exception(msg)
        except:
            err = sys.exc_info()
        (ec, ev, tb) = c.formatError(test, err)
        print ev
        if UNICODE_STRINGS:
            assert msg in ev
        else:
            assert msg.encode('utf-8') in ev
开发者ID:DerrickRice,项目名称:nose,代码行数:26,代码来源:test_logcapture_plugin.py


示例2: test_logging_datefmt_option

 def test_logging_datefmt_option(self):
     env = {'NOSE_LOGDATEFMT': '%H:%M:%S'}
     c = LogCapture()
     parser = OptionParser()
     c.addOptions(parser, env)
     options, args = parser.parse_args(['logging_datefmt'])
     c.configure(options, Config())
     eq_('%H:%M:%S', c.logdatefmt)
开发者ID:DerrickRice,项目名称:nose,代码行数:8,代码来源:test_logcapture_plugin.py


示例3: test_logging_format_option

 def test_logging_format_option(self):
     env = {'NOSE_LOGFORMAT': '++%(message)s++'}
     c = LogCapture()
     parser = OptionParser()
     c.addOptions(parser, env)
     options, args = parser.parse_args(['logging_format'])
     c.configure(options, Config())
     eq_('++%(message)s++', c.logformat)
开发者ID:DerrickRice,项目名称:nose,代码行数:8,代码来源:test_logcapture_plugin.py


示例4: test_get_logger

    def test_get_logger(self):
        lc = LogCapture()
        lc.begin()
        logger = log.get_logger()
        logger.debug('test-debug')
        logger.info('test-info')
        lc.end()

        self.assertEquals("giftwrap: INFO: test-info", lc.handler.buffer[0])
开发者ID:michaeltchapman,项目名称:giftwrap,代码行数:9,代码来源:test_log.py


示例5: test_get_logger

    def test_get_logger(self):
        lc = LogCapture()
        lc.begin()
        logger = logging.getLogger("giftwrap")
        logger.setLevel(logging.INFO)
        logger.debug("test-debug")
        logger.info("test-info")
        lc.end()

        self.assertEqual("giftwrap: INFO: test-info", lc.handler.buffer[0])
开发者ID:openstack,项目名称:giftwrap,代码行数:10,代码来源:test_log.py


示例6: test_default_options

    def test_default_options(self):
        c = LogCapture()
        parser = OptionParser()
        c.addOptions(parser)

        options, args = parser.parse_args(['default_options'])
        c.configure(options, Config())
        assert c.enabled
        eq_(LogCapture.logformat, c.logformat)
        eq_(LogCapture.clear, c.clear)
        eq_(LogCapture.filters, c.filters)
开发者ID:DerrickRice,项目名称:nose,代码行数:11,代码来源:test_logcapture_plugin.py


示例7: test_get_logger_debug

    def test_get_logger_debug(self):
        lc = LogCapture()
        lc.begin()
        logger = logging.getLogger('giftwrap')
        logger.setLevel(logging.DEBUG)
        logger.info('test-info')
        logger.debug('test-debug')
        lc.end()

        self.assertEquals("giftwrap: INFO: test-info", lc.handler.buffer[0])
        self.assertEquals("giftwrap: DEBUG: test-debug", lc.handler.buffer[1])
开发者ID:blueboxgroup,项目名称:giftwrap,代码行数:11,代码来源:test_log.py


示例8: test_loglevel

 def test_loglevel(self):
     c = LogCapture()
     parser = OptionParser()
     c.addOptions(parser, {})
     options, args = parser.parse_args(['--logging-level', 'INFO'])
     c.configure(options, Config())
     c.start()
     log = logging.getLogger("loglevel")
     log.debug("Hello")
     log.info("Goodbye")
     c.end()
     records = c.formatLogRecords()
     eq_(1, len(c.handler.buffer))
     eq_("loglevel: INFO: Goodbye", c.handler.buffer[0])
     eq_("loglevel: INFO: Goodbye", records[0])
开发者ID:DerrickRice,项目名称:nose,代码行数:15,代码来源:test_logcapture_plugin.py


示例9: test_captures_logging

 def test_captures_logging(self):
     c = LogCapture()
     parser = OptionParser()
     c.addOptions(parser, {})
     options, args = parser.parse_args([])
     c.configure(options, Config())
     c.start()
     log = logging.getLogger("foobar.something")
     log.debug("Hello")
     c.end()
     eq_(1, len(c.handler.buffer))
     eq_("foobar.something: DEBUG: Hello", c.handler.buffer[0])
开发者ID:DerrickRice,项目名称:nose,代码行数:12,代码来源:test_logcapture_plugin.py


示例10: test_logging_filter_exclude_and_include

 def test_logging_filter_exclude_and_include(self):
     env = {'NOSE_LOGFILTER': 'foo,-foo.bar'}
     c = LogCapture()
     parser = OptionParser()
     c.addOptions(parser, env)
     options, args = parser.parse_args(['foo'])
     print options, args
     c.configure(options, Config())
     c.start()
     for name in ['foo.yes', 'foo.bar', 'foo.bar.no', 'blah']:
         log = logging.getLogger(name)
         log.info("Hello %s" % name)
     c.end()
     records = c.formatLogRecords()
     eq_(1, len(records))
     assert records[0].startswith('foo.yes:'), records[0]
开发者ID:DerrickRice,项目名称:nose,代码行数:16,代码来源:test_logcapture_plugin.py


示例11: test_disable_option

    def test_disable_option(self):
        parser = OptionParser()
        c = LogCapture()
        c.addOptions(parser)
        options, args = parser.parse_args(['test_can_be_disabled_long',
                                           '--nologcapture'])
        c.configure(options, Config())
        assert not c.enabled

        env = {'NOSE_NOLOGCAPTURE': 1}
        c = LogCapture()
        parser = OptionParser()
        c.addOptions(parser, env)
        options, args = parser.parse_args(['test_can_be_disabled'])
        c.configure(options, Config())
        assert not c.enabled
开发者ID:DerrickRice,项目名称:nose,代码行数:16,代码来源:test_logcapture_plugin.py


示例12: test_non_propagating_loggers_handled

    def test_non_propagating_loggers_handled(self):
        c = LogCapture()
        parser = OptionParser()
        c.addOptions(parser, {})
        options, args = parser.parse_args([])
        c.configure(options, Config())

        logger = logging.getLogger('foo.yes')
        logger.propagate = False

        c.start()
        logger.debug("test message")
        c.end()

        records = c.formatLogRecords()
        eq_(1, len(records))
        assert records[0].startswith('foo.yes:'), records[0]
开发者ID:Averroes,项目名称:nose,代码行数:17,代码来源:test_logcapture_plugin.py


示例13: test_logging_filter_exclude

 def test_logging_filter_exclude(self):
     env = {'NOSE_LOGFILTER': '-foo,-bar'}
     c = LogCapture()
     parser = OptionParser()
     c.addOptions(parser, env)
     options, args = parser.parse_args(['foo'])
     print options, args
     c.configure(options, Config())
     c.start()
     for name in ['foobar.something', 'foo', 'foo.x', 'abara', 'bar.quux']:
         log = logging.getLogger(name)
         log.info("Hello %s" % name)
     c.end()
     records = c.formatLogRecords()
     eq_(2, len(records))
     assert records[0].startswith('foobar.something:'), records[0]
     assert records[1].startswith('abara:'), records[1]
开发者ID:DerrickRice,项目名称:nose,代码行数:17,代码来源:test_logcapture_plugin.py


示例14: test_custom_formatter

 def test_custom_formatter(self):
     c = LogCapture()
     c.logformat = '++%(message)s++'
     c.start()
     log = logging.getLogger("foobar.something")
     log.debug("Hello")
     c.end()
     records = c.formatLogRecords()
     eq_(1, len(records))
     eq_("++Hello++", records[0])
开发者ID:DerrickRice,项目名称:nose,代码行数:10,代码来源:test_logcapture_plugin.py


示例15: test_logging

def test_logging():
    c = LogCapture()
    parser = OptionParser()
    c.addOptions(parser, {})
    logger = klogger.get_logger("foo")
    logger = klogger.get_module_logger(__name__)
    c.start()

    logger.info("Goodbye")

    c.end()
    records = c.formatLogRecords()
    eq_("Goodbye", c.handler.buffer[0].msg)
    eq_("test.helpers.klogger_test", c.handler.buffer[0].name)
    eq_("test.helpers.klogger_test: INFO: Goodbye", records[0])
开发者ID:ashpool,项目名称:ketchlip,代码行数:15,代码来源:klogger_test.py


示例16: test_consistent_mutables

 def test_consistent_mutables(self):
     c = LogCapture()
     parser = OptionParser()
     c.addOptions(parser)
     c.start()
     log = logging.getLogger("mutable")
     mutable = { 'value': 1 }
     log.debug("%r", mutable)
     repr_1 = repr(mutable)
     mutable['value'] = 2
     log.debug("%r", mutable)
     repr_2 = repr(mutable)
     c.end()
     records = c.formatLogRecords()
     eq_("mutable: DEBUG: %s" % (repr_1,), records[0])
     eq_("mutable: DEBUG: %s" % (repr_2,), records[1])
开发者ID:DerrickRice,项目名称:nose,代码行数:16,代码来源:test_logcapture_plugin.py


示例17: test_builtin_logging_filtering

 def test_builtin_logging_filtering(self):
     c = LogCapture()
     c.logformat = '++%(message)s++'
     c.start()
     log = logging.getLogger("foobar.something")
     filtered = []
     class filter(object):
         def filter(record):
             filtered.append(record)
             return len(filtered) == 1
         filter = staticmethod(filter)
     c.handler.addFilter(filter)
     log.debug("Hello")
     log.debug("World")
     c.end()
     eq_(2, len(filtered))
     records = c.formatLogRecords()
     eq_(1, len(records))
     eq_("++Hello++", records[0])
开发者ID:BAG-CK,项目名称:nose,代码行数:19,代码来源:test_logcapture_plugin.py


示例18: test_clears_all_existing_log_handlers

    def test_clears_all_existing_log_handlers(self):
        c = LogCapture()
        parser = OptionParser()
        c.addOptions(parser, {})
        options, args = parser.parse_args(['--logging-clear-handlers'])
        c.configure(options, Config())
        eq_(c.clear, True)

        def mktest():
            class TC(unittest.TestCase):
                def runTest(self):
                    pass
            test = TC()
            return test

        logging.getLogger().addHandler(StreamHandler(sys.stdout))
        log = logging.getLogger("dummy")
        log.addHandler(StreamHandler(sys.stdout))

        c.start()
        c.beforeTest(mktest())
        c.end()

        if py27:
            expect = ["<class 'nose.plugins.logcapture.MyMemoryHandler'>"]
        else:
            expect = ['nose.plugins.logcapture.MyMemoryHandler']
        eq_([str(c.__class__) for c in logging.getLogger().handlers],
            expect)
        eq_([str(c.__class__) for c in logging.getLogger("dummy").handlers],
            [])
开发者ID:DerrickRice,项目名称:nose,代码行数:31,代码来源:test_logcapture_plugin.py


示例19: test_capture_data

    def test_capture_data(self):
        c = LogCapture()
        parser = OptionParser()
        c.addOptions(parser, {})
        options, args = parser.parse_args([])
        c.configure(options, Config())
        c.start()

        def mktest():
            class TC(unittest.TestCase):
                def runTest(self):
                    pass
            test = TC()
            return test
        test = mktest()

        c.beforeTest(test)

        assert hasattr(test, 'logCaptureData')
        eq_(test.logCaptureData.isFinished(), False)
        eq_(test.logCaptureData.getText(), "")

        log = logging.getLogger("foobar.something")
        log.debug("ordinary string log")

        eq_(test.logCaptureData.getText(),
                "foobar.something: DEBUG: ordinary string log")
        eq_(len(test.logCaptureData.getRecords()), 1)
        eq_(test.logCaptureData.isFinished(), False)

        c.afterTest(test)
        
        eq_(test.logCaptureData.isFinished(), True)

        log.debug("NOT PRESENT")

        eq_(test.logCaptureData.getText(),
                "foobar.something: DEBUG: ordinary string log")
        eq_(len(test.logCaptureData.getRecords()), 1)
        eq_(test.logCaptureData._handler, None) # eh. whitebox.

        c.end()
开发者ID:DerrickRice,项目名称:nose,代码行数:42,代码来源:test_logcapture_plugin.py



注:本文中的nose.plugins.logcapture.LogCapture类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python xunit.Xunit类代码示例发布时间:2022-05-27
下一篇:
Python doctests.Doctest类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap