本文整理汇总了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)
示例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)
示例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)
示例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))
示例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()
示例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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)