# Path: matl_online/tasks.py
# class OutputHandler(StreamHandler):
#     """Custom handler for converting logged data to socket events."""
# 
#     def __init__(self, task, *args, **kwargs):
#         """Initialize the handler with the task we are handling."""
#         StreamHandler.__init__(self, *args, **kwargs)
#         self.task = task
#         self.clear()
# 
#     def clear(self):
#         """Clear all messages that have been logged so far."""
#         self.contents = []
# 
#     def messages(self):
#         """Concatenate all messages into a long stream."""
#         return '\n'.join([x for x in self.contents])
# 
#     def send(self):
#         """Send a message out to the specified rooms."""
#         output = parse_matl_results(self.messages())
#         result = {'data': output, 'session': self.task.session_id}
#         socket.emit('status', result, room=self.task.session_id)
#         return result
# 
#     def emit(self, record):
#         """Overloaded emit method to receive LogRecord instances."""
#         # Look to see if there are any special commands in here. These
#         # commands will clear the output:
#         #
#         #   1. [PAUSE]  Send everything that we have so far
#         #   2. [CLC]    Send an empty message and clear contents
#         #   3. [IMAGE]  FUTURE ENCODING TO BASE64
# 
#         if record.levelno == logging.INFO:
#             self.process_message(record.msg)
# 
#     def process_message(self, message):
#         """Append a message to be send back to the user."""
#         print(message)
# 
#         if message == '[PAUSE]':
#             # For now we send the entire message again. Consider a better
#             # approach (i.e. adding a field to the result that says to
#             # flush prior to display)
#             self.send()
#             return
#         elif message == '[CLC]':
#             self.send()
#             self.clear()
#             return
#         elif message.startswith('warning:'):
#             return
#         elif message.startswith('MATL run-time error:'):
#             for item in message.split('\n'):
#                 self.contents.append('[STDERR]' + item)
# 
#             return
# 
#         self.contents.append(message)


from matl_online.tasks import OutputHandler
"""Unit tests for checking our realtime log handler."""



class TestLogHandler:
    """Series of tests for the OutputHandler logging handler."""

    def test_initialization(self, logger):
        """Make sure that all necessary properties are set."""
        task = type('task', (object,), {'session_id': '123'})

# Path: matl_online/tasks.py
# class OutputHandler(StreamHandler):
#     """Custom handler for converting logged data to socket events."""
# 
#     def __init__(self, task, *args, **kwargs):
#         """Initialize the handler with the task we are handling."""
#         StreamHandler.__init__(self, *args, **kwargs)
#         self.task = task
#         self.clear()
# 
#     def clear(self):
#         """Clear all messages that have been logged so far."""
#         self.contents = []
# 
#     def messages(self):
#         """Concatenate all messages into a long stream."""
#         return '\n'.join([x for x in self.contents])
# 
#     def send(self):
#         """Send a message out to the specified rooms."""
#         output = parse_matl_results(self.messages())
#         result = {'data': output, 'session': self.task.session_id}
#         socket.emit('status', result, room=self.task.session_id)
#         return result
# 
#     def emit(self, record):
#         """Overloaded emit method to receive LogRecord instances."""
#         # Look to see if there are any special commands in here. These
#         # commands will clear the output:
#         #
#         #   1. [PAUSE]  Send everything that we have so far
#         #   2. [CLC]    Send an empty message and clear contents
#         #   3. [IMAGE]  FUTURE ENCODING TO BASE64
# 
#         if record.levelno == logging.INFO:
#             self.process_message(record.msg)
# 
#     def process_message(self, message):
#         """Append a message to be send back to the user."""
#         print(message)
# 
#         if message == '[PAUSE]':
#             # For now we send the entire message again. Consider a better
#             # approach (i.e. adding a field to the result that says to
#             # flush prior to display)
#             self.send()
#             return
#         elif message == '[CLC]':
#             self.send()
#             self.clear()
#             return
#         elif message.startswith('warning:'):
#             return
#         elif message.startswith('MATL run-time error:'):
#             for item in message.split('\n'):
#                 self.contents.append('[STDERR]' + item)
# 
#             return
# 
#         self.contents.append(message)


# Path: tests/test_log_handler.py
from matl_online.tasks import OutputHandler

"""Unit tests for checking our realtime log handler."""



class TestLogHandler:
    """Series of tests for the OutputHandler logging handler."""

    def test_initialization(self, logger):
        """Make sure that all necessary properties are set."""
        task = type('task', (object,), {'session_id': '123'})

        handler = OutputHandler(task)