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


Python log.ColorFormatter类代码示例

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


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

示例1: test_format_raises

    def test_format_raises(self, safe_str):
        x = ColorFormatter()

        def on_safe_str(s):
            try:
                raise ValueError("foo")
            finally:
                safe_str.side_effect = None

        safe_str.side_effect = on_safe_str

        @python_2_unicode_compatible
        class Record(object):
            levelname = "ERROR"
            msg = "HELLO"
            exc_info = 1
            exc_text = "error text"
            stack_info = None

            def __str__(self):
                return on_safe_str("")

            def getMessage(self):
                return self.msg

        record = Record()
        safe_str.return_value = record

        msg = x.format(record)
        self.assertIn("<Unrepresentable", msg)
        self.assertEqual(safe_str.call_count, 1)
开发者ID:m4ddav3,项目名称:celery,代码行数:31,代码来源:test_log.py

示例2: test_format_raises

    def test_format_raises(self, safe_str):
        x = ColorFormatter('HELLO')

        def on_safe_str(s):
            try:
                raise ValueError('foo')
            finally:
                safe_str.side_effect = None
        safe_str.side_effect = on_safe_str

        class Record(object):
            levelname = 'ERROR'
            msg = 'HELLO'
            exc_text = 'error text'
            stack_info = None

            def __str__(self):
                return on_safe_str('')

            def getMessage(self):
                return self.msg

        record = Record()
        safe_str.return_value = record

        x.format(record)
        self.assertIn('<Unrepresentable', record.msg)
        self.assertEqual(safe_str.call_count, 2)
开发者ID:DotNetWebs,项目名称:celery,代码行数:28,代码来源:test_log.py

示例3: test_formatException_not_string

 def test_formatException_not_string(self, fe, safe_str):
     x = ColorFormatter('HELLO')
     value = KeyError()
     fe.return_value = value
     self.assertIs(x.formatException(value), value)
     self.assertTrue(fe.called)
     self.assertFalse(safe_str.called)
开发者ID:DotNetWebs,项目名称:celery,代码行数:7,代码来源:test_log.py

示例4: test_format_object

 def test_format_object(self, _format):
     x = ColorFormatter()
     x.use_color = True
     record = Mock()
     record.levelname = 'ERROR'
     record.msg = object()
     self.assertTrue(x.format(record))
开发者ID:fatelei,项目名称:celery,代码行数:7,代码来源:test_log.py

示例5: test_formatException_not_string

 def test_formatException_not_string(self, fe, safe_str):
     x = ColorFormatter()
     value = KeyError()
     fe.return_value = value
     self.assertIs(x.formatException(value), value)
     fe.assert_called()
     safe_str.assert_not_called()
开发者ID:m4ddav3,项目名称:celery,代码行数:7,代码来源:test_log.py

示例6: test_format_raises

    def test_format_raises(self, safe_str):
        x = ColorFormatter()

        def on_safe_str(s):
            try:
                raise ValueError('foo')
            finally:
                safe_str.side_effect = None
        safe_str.side_effect = on_safe_str

        @python_2_unicode_compatible
        class Record(object):
            levelname = 'ERROR'
            msg = 'HELLO'
            exc_info = 1
            exc_text = 'error text'
            stack_info = None

            def __str__(self):
                return on_safe_str('')

            def getMessage(self):
                return self.msg

        record = Record()
        safe_str.return_value = record

        msg = x.format(record)
        assert '<Unrepresentable' in msg
        assert safe_str.call_count == 1
开发者ID:maniacs-ops,项目名称:celery,代码行数:30,代码来源:test_log.py

示例7: test_format_raises_no_color

 def test_format_raises_no_color(self, safe_str):
     x = ColorFormatter(use_color=False)
     record = Mock()
     record.levelname = 'ERROR'
     record.msg = 'HELLO'
     record.exc_text = 'error text'
     x.format(record)
     self.assertEqual(safe_str.call_count, 1)
开发者ID:fatelei,项目名称:celery,代码行数:8,代码来源:test_log.py

示例8: test_format_raises_no_color

 def test_format_raises_no_color(self, safe_str):
     x = ColorFormatter("HELLO", False)
     record = Mock()
     record.levelname = "ERROR"
     record.msg = "HELLO"
     record.exc_text = "error text"
     x.format(record)
     self.assertEqual(safe_str.call_count, 1)
开发者ID:clvrobj,项目名称:celery,代码行数:8,代码来源:test_log.py

示例9: test_formatException_bytes

 def test_formatException_bytes(self, safe_str, fe):
     x = ColorFormatter()
     fe.return_value = b'HELLO'
     try:
         raise Exception()
     except Exception:
         self.assertTrue(x.formatException(sys.exc_info()))
     if sys.version_info[0] == 2:
         self.assertTrue(safe_str.called)
开发者ID:fatelei,项目名称:celery,代码行数:9,代码来源:test_log.py

示例10: test_format_raises_no_color

 def test_format_raises_no_color(self, safe_str):
     if sys.version_info[0] == 3:
         raise SkipTest('py3k')
     x = ColorFormatter('HELLO', False)
     record = Mock()
     record.levelname = 'ERROR'
     record.msg = 'HELLO'
     record.exc_text = 'error text'
     x.format(record)
     self.assertEqual(safe_str.call_count, 1)
开发者ID:DotNetWebs,项目名称:celery,代码行数:10,代码来源:test_log.py

示例11: format

 def format(self, record):
     task = get_current_task()
     if task and task.request:
         record.__dict__.update(task_id=task.request.id, task_name=task.name)
     else:
         record.__dict__.setdefault("task_name", "???")
         record.__dict__.setdefault("task_id", "???")
     return ColorFormatter.format(self, record)
开发者ID:AndrewBloody,项目名称:DUBALU_SMS,代码行数:8,代码来源:log.py

示例12: format

 def format(self, record):
     task = get_current_task()
     if task:
         record.__dict__.update(task_id=task.request.id,
                                task_name=task.name)
     else:
         record.__dict__.setdefault('task_name', '???')
         record.__dict__.setdefault('task_id', '???')
     return ColorFormatter.format(self, record)
开发者ID:rwillmer,项目名称:celery,代码行数:9,代码来源:log.py

示例13: test_format_raises

    def test_format_raises(self, safe_str):
        x = ColorFormatter("HELLO")

        def on_safe_str(s):
            try:
                raise ValueError("foo")
            finally:
                safe_str.side_effect = None
        safe_str.side_effect = on_safe_str

        record = Mock()
        record.levelname = "ERROR"
        record.msg = "HELLO"
        record.exc_text = "error text"
        safe_str.return_value = record

        x.format(record)
        self.assertIn("<Unrepresentable", record.msg)
        self.assertEqual(safe_str.call_count, 2)
开发者ID:clvrobj,项目名称:celery,代码行数:19,代码来源:test_log.py

示例14: test_formatException_string

 def test_formatException_string(self, safe_str, fe, value='HELLO'):
     x = ColorFormatter(value)
     fe.return_value = value
     self.assertTrue(x.formatException(value))
     if sys.version_info[0] == 2:
         self.assertTrue(safe_str.called)
开发者ID:DotNetWebs,项目名称:celery,代码行数:6,代码来源:test_log.py

示例15: test_formatException_string

 def test_formatException_string(self, safe_str, fe, value="HELLO"):
     x = ColorFormatter(value)
     fe.return_value = value
     self.assertTrue(x.formatException(value))
     self.assertTrue(safe_str.called)
开发者ID:clvrobj,项目名称:celery,代码行数:5,代码来源:test_log.py


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