当前位置: 首页>>代码示例>>Python>>正文


Python logging.raiseExceptions方法代码示例

本文整理汇总了Python中logging.raiseExceptions方法的典型用法代码示例。如果您正苦于以下问题:Python logging.raiseExceptions方法的具体用法?Python logging.raiseExceptions怎么用?Python logging.raiseExceptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在logging的用法示例。


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

示例1: test_error_handling

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_error_handling(self):
        h = TestStreamHandler(BadStream())
        r = logging.makeLogRecord({})
        old_raise = logging.raiseExceptions

        try:
            h.handle(r)
            self.assertIs(h.error_record, r)

            h = logging.StreamHandler(BadStream())
            with support.captured_stderr() as stderr:
                h.handle(r)
                msg = '\nRuntimeError: deliberate mistake\n'
                self.assertIn(msg, stderr.getvalue())

            logging.raiseExceptions = False
            with support.captured_stderr() as stderr:
                h.handle(r)
                self.assertEqual('', stderr.getvalue())
        finally:
            logging.raiseExceptions = old_raise

# -- The following section could be moved into a server_helper.py module
# -- if it proves to be of wider utility than just test_logging 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:26,代码来源:test_logging.py

示例2: test_error_handling

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_error_handling(self):
        h = TestStreamHandler(BadStream())
        r = logging.makeLogRecord({})
        old_raise = logging.raiseExceptions
        old_stderr = sys.stderr
        try:
            h.handle(r)
            self.assertIs(h.error_record, r)
            h = logging.StreamHandler(BadStream())
            sys.stderr = sio = io.StringIO()
            h.handle(r)
            self.assertIn('\nRuntimeError: deliberate mistake\n',
                          sio.getvalue())
            logging.raiseExceptions = False
            sys.stderr = sio = io.StringIO()
            h.handle(r)
            self.assertEqual('', sio.getvalue())
        finally:
            logging.raiseExceptions = old_raise
            sys.stderr = old_stderr

# -- The following section could be moved into a server_helper.py module
# -- if it proves to be of wider utility than just test_logging 
开发者ID:IronLanguages,项目名称:ironpython3,代码行数:25,代码来源:test_logging.py

示例3: Parser_debug

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def Parser_debug(enable, stream=None):
    '''
    Enables/Disables debug logger for parser.py

    NOTE: This is not really multi-thread friendly

    @param stream: StringIO stream to use
    @param enable: Enable/disable debug stream
    '''
    global debug
    debug = enable

    if enable:
        logging.raiseExceptions = False
        log.setLevel(logging.DEBUG)
        ch = logging.StreamHandler(stream)
        log.addHandler(ch) 
开发者ID:kiibohd,项目名称:kll,代码行数:19,代码来源:parser.py

示例4: callHandlers

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def callHandlers(self, record):
		# this is the same as Python 3.5's logging.Logger.callHandlers
		c = self
		found = 0
		while c:
			for hdlr in c.handlers:
				found = found + 1
				if record.levelno >= hdlr.level:
					hdlr.handle(record)
			if not c.propagate:
				c = None  # break out
			else:
				c = c.parent
		if (found == 0):
			if logging.lastResort:
				if record.levelno >= logging.lastResort.level:
					logging.lastResort.handle(record)
			elif logging.raiseExceptions and not self.manager.emittedNoHandlerWarning:
				sys.stderr.write("No handlers could be found for logger"
								 " \"%s\"\n" % self.name)
				self.manager.emittedNoHandlerWarning = True 
开发者ID:MitchTalmadge,项目名称:Emoji-Tools,代码行数:23,代码来源:py23.py

示例5: test_unknown_exception

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_unknown_exception(self, mock_session):
        """Test botocore general ClientError."""
        logging.disable(logging.NOTSET)
        mock_session.client = MagicMock()
        unit_crawler = AWSOrgUnitCrawler(self.account)
        unit_crawler._init_session()
        unit_crawler._client.list_roots.side_effect = Exception("unknown error")
        with self.assertLogs(logger=crawler_log, level=logging.raiseExceptions):
            unit_crawler.crawl_account_hierarchy() 
开发者ID:project-koku,项目名称:koku,代码行数:11,代码来源:test_aws_org_unit_crawler.py

示例6: handleError

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def handleError(self, record: logging.LogRecord) -> None:
        if logging.raiseExceptions:
            # Fail the test if the log message is bad (emit failed).
            # The default behavior of logging is to print "Logging error"
            # to stderr with the call stack and some extra details.
            # pytest wants to make such mistakes visible during testing.
            raise 
开发者ID:pytest-dev,项目名称:pytest,代码行数:9,代码来源:logging.py

示例7: test_last_resort

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_last_resort(self):
        # Test the last resort handler
        root = self.root_logger
        root.removeHandler(self.root_hdlr)
        old_lastresort = logging.lastResort
        old_raise_exceptions = logging.raiseExceptions

        try:
            with support.captured_stderr() as stderr:
                root.debug('This should not appear')
                self.assertEqual(stderr.getvalue(), '')
                root.warning('Final chance!')
                self.assertEqual(stderr.getvalue(), 'Final chance!\n')

            # No handlers and no last resort, so 'No handlers' message
            logging.lastResort = None
            with support.captured_stderr() as stderr:
                root.warning('Final chance!')
                msg = 'No handlers could be found for logger "root"\n'
                self.assertEqual(stderr.getvalue(), msg)

            # 'No handlers' message only printed once
            with support.captured_stderr() as stderr:
                root.warning('Final chance!')
                self.assertEqual(stderr.getvalue(), '')

            # If raiseExceptions is False, no message is printed
            root.manager.emittedNoHandlerWarning = False
            logging.raiseExceptions = False
            with support.captured_stderr() as stderr:
                root.warning('Final chance!')
                self.assertEqual(stderr.getvalue(), '')
        finally:
            root.addHandler(self.root_hdlr)
            logging.lastResort = old_lastresort
            logging.raiseExceptions = old_raise_exceptions 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:38,代码来源:test_logging.py

示例8: setUp

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def setUp(self):
        super(ShutdownTest, self).setUp()
        self.called = []

        raise_exceptions = logging.raiseExceptions
        self.addCleanup(setattr, logging, 'raiseExceptions', raise_exceptions) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_logging.py

示例9: test_with_other_error_in_acquire_without_raise

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_acquire_without_raise(self):
        logging.raiseExceptions = False
        self._test_with_failure_in_method('acquire', IndexError) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_logging.py

示例10: test_with_other_error_in_flush_without_raise

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_flush_without_raise(self):
        logging.raiseExceptions = False
        self._test_with_failure_in_method('flush', IndexError) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_logging.py

示例11: test_with_other_error_in_acquire_with_raise

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_acquire_with_raise(self):
        logging.raiseExceptions = True
        self.assertRaises(IndexError, self._test_with_failure_in_method,
                          'acquire', IndexError) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_logging.py

示例12: test_with_other_error_in_flush_with_raise

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_flush_with_raise(self):
        logging.raiseExceptions = True
        self.assertRaises(IndexError, self._test_with_failure_in_method,
                          'flush', IndexError) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_logging.py

示例13: test_with_other_error_in_close_with_raise

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_with_other_error_in_close_with_raise(self):
        logging.raiseExceptions = True
        self.assertRaises(IndexError, self._test_with_failure_in_method,
                          'close', IndexError) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:6,代码来源:test_logging.py

示例14: test_log_invalid_level_with_raise

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_log_invalid_level_with_raise(self):
        with support.swap_attr(logging, 'raiseExceptions', True):
            self.assertRaises(TypeError, self.logger.log, '10', 'test message') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_logging.py

示例15: test_log_invalid_level_no_raise

# 需要导入模块: import logging [as 别名]
# 或者: from logging import raiseExceptions [as 别名]
def test_log_invalid_level_no_raise(self):
        with support.swap_attr(logging, 'raiseExceptions', False):
            self.logger.log('10', 'test message')  # no exception happens 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:5,代码来源:test_logging.py


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