def test_process_one_message(): """ Test we can process one message. """ # Build our expected message message = {'module': 'log', 'funcName': 'log_exception', 'message': 'GET http://localhost:5000/folders/5/emails', 'filename': 'log.py', 'lineno': 214, 'args': [], 'exc_text': 'Traceback (most recent call last):', 'kind': 'app', 'pathname': '/some/path.py', 'source': 'eric-desktop'} message_params = {k: v for k, v in message.items() # Intentionally ignoring Pylint's reservations about # accessing private members here # pylint: disable=W0212 if k in UniqueMessage._fields} # pylint: enable=W0212 expected_message = _package_unique_message(message_params) # Set up mocks for the queue and buffer. message_queue = Mock() message_queue.get.return_value = message message_buffer = Mock() _process_one_message(message_queue, message_buffer) # Make sure we sent this message to the buffer as expected. message_buffer.add.assert_called_once_with(expected_message, message['source'])
def test_customization_msg_impl(): """ Test that the user can customize the impl of UniqueMessage and the output formats. """ message_queue = Mock() message_buffer = Mock() message_params = dict(x=1, y=2, z=3, src='src') message_queue.get.return_value = message_params _process_one_message(message_queue, message_buffer) message_buffer.add.assert_called_once_with(CustomUniqueError(1, 2, 3), 'src')
def test_process_one_fill_exc(): """ Test we gracefully handle a message where the message file is split over multiple lines. This means the stack trace is also the message. In this case we only got message and not exc_text, make sure we fill exc text from message. We want to clip it so the message is only the first line of the message. """ # Build our expected message message = {'module': 'log', 'funcName': 'log_exception', 'message': '1\n2\n3\n', 'filename': 'log.py', 'lineno': 214, 'args': [], 'kind': 'app', 'pathname': '/some/path.py', 'source': 'eric-desktop'} message_params = {k: v for k, v in message.items() # Intentionally ignoring Pylint's reservations about # accessing private members here # pylint: disable=W0212 if k in UniqueMessage._fields} # pylint: enable=W0212 # Make sure we clip after the newline and fill exc_text message_params['message'] = '1' message_params['exc_text'] = '1\n2\n3\n' expected_message = _package_unique_message(message_params) # Set up mocks for the queue and buffer. message_queue = Mock() message_queue.get.return_value = message message_buffer = Mock() _process_one_message(message_queue, message_buffer) # Make sure we sent this message to the buffer as expected. message_buffer.add.assert_called_once_with(expected_message, message['source'])