本文整理汇总了Python中unittest.mock.Mock.msg方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.msg方法的具体用法?Python Mock.msg怎么用?Python Mock.msg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.msg方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_full_message
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def test_get_full_message():
"""Test getting a full message.
"""
record = Mock()
message = 'Message'
record.msg = message
record.levelno = 10
record.exc_info = None
handler = logger.DSNHandler('dsn', 'qa', 'logging', '1.0.0')
assert handler.get_full_message(record) == message
示例2: _filter_twenty_records_over_two_seconds
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def _filter_twenty_records_over_two_seconds(self, f):
mock_record = Mock()
mock_record.msg = 'test message'
result = []
for _ in range(20):
result.append(f.filter(mock_record))
self.mock_time.return_value += 0.1
return result
示例3: test_rate_limit_messages_matching_substring
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def test_rate_limit_messages_matching_substring(self):
config = {'match': ['rate limited']}
f = RateLimitingFilter(rate=1, per=1, burst=1, **config)
mock_matching_record = Mock()
mock_matching_record.msg = 'a rate limited test message'
mock_non_matching_record = Mock()
mock_non_matching_record.msg = 'a different test message'
result = []
for _ in range(20):
if f.filter(mock_matching_record):
result.append(mock_matching_record.msg) # Only 2 of these get logged as they match the substring
if f.filter(mock_non_matching_record):
result.append(mock_non_matching_record.msg) # 20 of these get logged as they don't match
self.mock_time.return_value += 0.1
self.assertEqual(len([m for m in result if 'a rate limited test message' in m]), 2)
self.assertEqual(result.count('a different test message'), 20)
示例4: test_append_num_limited_records_to_message
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def test_append_num_limited_records_to_message(self):
filtered = []
f = RateLimitingFilter(rate=1, per=1, burst=4)
for _ in range(30):
mock_record = Mock()
mock_record.msg = 'test message'
if f.filter(mock_record):
filtered.append(mock_record)
self.mock_time.return_value += 0.1
self.assertEqual(len(filtered), 6)
self.assertTrue(filtered[4].msg.endswith(os.linesep + '... 6 additional messages suppressed'))
self.assertTrue(filtered[5].msg.endswith(os.linesep + '... 9 additional messages suppressed'))
示例5: test_rate_limit_messages_automatically
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def test_rate_limit_messages_automatically(self):
config = {'match': 'auto'}
f = RateLimitingFilter(rate=1, per=1, burst=1, **config)
result = []
for i in range(20):
mock_varying_record = Mock()
mock_varying_record.msg = 'a rate limited varying message: {varying}'.format(varying=i)
mock_rate_limited_record = Mock()
mock_rate_limited_record.msg = 'a completely different message'
if f.filter(mock_varying_record):
# Only 2 of these get logged as they are considered the same message,
# even though they are not identical
result.append(mock_varying_record.msg)
if f.filter(mock_rate_limited_record):
# Only 2 of these get logged as they are the all identical
result.append(mock_rate_limited_record.msg)
self.mock_time.return_value += 0.1
self.assertEqual(len([m for m in result if 'a rate limited varying message' in m]), 2)
self.assertEqual(len([m for m in result if 'a completely different message' in m]), 2)
示例6: test_emit_message_with_normal_exception
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def test_emit_message_with_normal_exception(session):
"""Test emiting a message with a normal exception thrown from post request.
"""
session.post = Mock(side_effect=Exception())
record = Mock()
record.msg = 'Message'
record.levelno = 10
record.exc_info = None
record.correlation_id = uuid.uuid1()
handler = logger.DSNHandler('dsn', 'qa', 'logging', '1.0.0')
handler.handleError = Mock()
handler.emit(record)
handler.handleError.assert_called_with(record)
示例7: test_session_post_called_on_message_emit
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def test_session_post_called_on_message_emit(session):
"""Test session post called when a message is emitted.
"""
record = Mock()
message = 'Message'
correlation_id = uuid.uuid1()
record.levelno = 10
record.msg = message
record.created = datetime.now().timestamp()
record.exc_info = None
record.correlation_id = correlation_id
handler = logger.DSNHandler('dsn', 'qa', 'logging', '1.0.0')
handler.emit(record)
assert session.post.called
示例8: test_emit_message_on_post_failure
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import msg [as 别名]
def test_emit_message_on_post_failure(session):
"""Test emiting a message with the session post triggering an exception.
"""
# SystemExit won't be an error that will be throw, it will just
# be an exception. To test this is
session.post = Mock(side_effect=SystemExit())
record = Mock()
record.msg = 'Message'
record.levelno = 10
record.created = datetime.now().timestamp()
record.exc_info = None
record.correlation_id = uuid.uuid1()
handler = logger.DSNHandler('dsn', 'qa', 'logging', '1.0.0')
with pytest.raises(SystemExit):
handler.emit(record)