# Path: deepstreampy/message/message_parser.py
# def parse(raw_messages, client):
# def _parse_message(message, client):
# def convert_typed(value, client):


from deepstreampy.message import message_parser
from behave import given, when, then
from tornado import testing
    from unittest import mock
import json
import sys
import config
    import mock
    expected = message.replace("|", chr(31)).replace("+", chr(30))
    all_messages = context.received_messages('/deepstream')
    assert expected not in all_messages, all_messages


@then(u'the server received the message {message}')
def received_message(context, message):
    expected = message.replace("|", chr(31)).replace("+", chr(30))

    while True:
        if expected in context.received_messages('/deepstream'):
            return

        msg_future = next(iter(
            context.connections('/deepstream'))).message_future()
        yield msg_future

    raise AssertionError("{0} not received".format(message))


@when(u'the connection to the server is lost')
def connection_lost(context):
    for conn in context.connections('/deepstream'):
        conn.close()
    del context.received_messages('/deepstream')[:]
    context.server.stop()


@when(u'the connection to the server is reestablished')
@testing.gen_test

# Path: deepstreampy/message/message_parser.py
# def parse(raw_messages, client):
# def _parse_message(message, client):
# def convert_typed(value, client):


# Path: features/steps/server.py
from deepstreampy.message import message_parser
from behave import given, when, then
from tornado import testing
    from unittest import mock
import json
import sys
import config
    import mock

    expected = message.replace("|", chr(31)).replace("+", chr(30))
    all_messages = context.received_messages('/deepstream')
    assert expected not in all_messages, all_messages


@then(u'the server received the message {message}')
def received_message(context, message):
    expected = message.replace("|", chr(31)).replace("+", chr(30))

    while True:
        if expected in context.received_messages('/deepstream'):
            return

        msg_future = next(iter(
            context.connections('/deepstream'))).message_future()
        yield msg_future

    raise AssertionError("{0} not received".format(message))


@when(u'the connection to the server is lost')
def connection_lost(context):
    for conn in context.connections('/deepstream'):
        conn.close()
    del context.received_messages('/deepstream')[:]
    context.server.stop()


@when(u'the connection to the server is reestablished')
@testing.gen_test

def connection_reestablished(context):