# Path: matl_online/app.py
# def create_app(config_object=ProdConfig):
#     """Application factory for creating flask apps."""
#     app = Flask(__name__)
#     app.config.from_object(config_object)
#     register_extensions(app)
#     register_blueprints(app)
#     return app
# 
# Path: matl_online/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
# 
# Path: matl_online/extensions.py

# 
# Path: matl_online/settings.py
# class TestConfig(Config):
#     """Test configuration."""
# 
#     ENV = 'test'
#     TESTING = True
#     DEBUG = True
#     SQLALCHEMY_DATABASE_URI = 'sqlite://'
# 
#     IMGUR_CLIENT_ID = 'imgur_test'
# 
#     WTF_CSRF_ENABLED = False
# 
#     # Ensure that celery tasks are executed locally
#     CELERY_ALWAYS_EAGER = True
# 
#     PRESERVE_CONTEXT_ON_EXCEPTION = False
# 
#     # Create a bogus GA Universal ID for testing
#     GOOGLE_ANALYTICS_UNIVERSAL_ID = 'nonsense'
# 
#     ROLLBAR_ENV = 'testing'
# 
# 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)


import logging
import os
import pytest
import uuid
from flask_socketio import SocketIOTestClient
from webtest import TestApp
from matl_online.app import create_app
from matl_online.database import db as _db
from matl_online.extensions import socketio
from matl_online.settings import TestConfig
from matl_online.tasks import OutputHandler
    logger.setLevel(logging.INFO)

    yield logger

    for handler in logger.handlers:
        # In the special case where an OutputHandler is registered, we want
        # to clear out the message queue
        if isinstance(handler, OutputHandler):
            handler.clear()

    logger.handlers = []


@pytest.fixture
def moctave(mocker, logger):
    """Mock version of OctaveEngine to monitor calls to octave."""
    moctave = mocker.patch('matl_online.tasks.octave')
    moctave.evals = list()

    def moctave_eval(*args, **kwargs):
        moctave.evals.append(*args)

    moctave.eval = moctave_eval
    moctave.logger = logger
    return moctave


@pytest.fixture(scope='function')
def db(app):
    """Database instance."""

# Path: matl_online/app.py
# def create_app(config_object=ProdConfig):
#     """Application factory for creating flask apps."""
#     app = Flask(__name__)
#     app.config.from_object(config_object)
#     register_extensions(app)
#     register_blueprints(app)
#     return app
# 
# Path: matl_online/database.py
# class CRUDMixin(object):
# class Model(CRUDMixin, db.Model):
#     def create(cls, **kwargs):
#     def update(self, commit=True, **kwargs):
#     def save(self, commit=True):
#     def delete(self, commit=True):
# 
# Path: matl_online/extensions.py

# 
# Path: matl_online/settings.py
# class TestConfig(Config):
#     """Test configuration."""
# 
#     ENV = 'test'
#     TESTING = True
#     DEBUG = True
#     SQLALCHEMY_DATABASE_URI = 'sqlite://'
# 
#     IMGUR_CLIENT_ID = 'imgur_test'
# 
#     WTF_CSRF_ENABLED = False
# 
#     # Ensure that celery tasks are executed locally
#     CELERY_ALWAYS_EAGER = True
# 
#     PRESERVE_CONTEXT_ON_EXCEPTION = False
# 
#     # Create a bogus GA Universal ID for testing
#     GOOGLE_ANALYTICS_UNIVERSAL_ID = 'nonsense'
# 
#     ROLLBAR_ENV = 'testing'
# 
# 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/conftest.py
import logging
import os
import pytest
import uuid
from flask_socketio import SocketIOTestClient
from webtest import TestApp
from matl_online.app import create_app
from matl_online.database import db as _db
from matl_online.extensions import socketio
from matl_online.settings import TestConfig
from matl_online.tasks import OutputHandler

    logger.setLevel(logging.INFO)

    yield logger

    for handler in logger.handlers:
        # In the special case where an OutputHandler is registered, we want
        # to clear out the message queue
        if isinstance(handler, OutputHandler):
            handler.clear()

    logger.handlers = []


@pytest.fixture
def moctave(mocker, logger):
    """Mock version of OctaveEngine to monitor calls to octave."""
    moctave = mocker.patch('matl_online.tasks.octave')
    moctave.evals = list()

    def moctave_eval(*args, **kwargs):
        moctave.evals.append(*args)

    moctave.eval = moctave_eval
    moctave.logger = logger
    return moctave


@pytest.fixture(scope='function')
def db(app):
    """Database instance."""

    _db.app = app