# 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
            context.connections('/deepstream'))).write_message(message)


@then(u'the server has {num_connections} active connections')
def server_num_connections(context, num_connections):
    connections_count = context.num_connections('/deepstream')
    assert connections_count == int(num_connections), (str(connections_count) +
                                                       " active connections.")


@then(u'the second server has {num_connections} active connections')
def second_server_num_connections(context, num_connections):
    connections_count = context.num_connections('/deepstream2')
    assert connections_count == int(num_connections), (str(connections_count) +
                                                       " active connections.")


@then(u'the last message the server recieved is {message}')
def server_last_message(context, message):
    expected = message.replace("|", chr(31)).replace("+", chr(30))
    expected = expected.replace("<FIRST_SERVER_URL>", config.FIRST_SERVER_URL)
    parsed_expected = message_parser.parse(expected, context.client)[0]

    if context.client._connection._url == config.FIRST_SERVER_URL:
        messages = context.received_messages('/deepstream')
    else:
        messages = context.received_messages('/deepstream2')

    while True:
        if messages:

# 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

            context.connections('/deepstream'))).write_message(message)


@then(u'the server has {num_connections} active connections')
def server_num_connections(context, num_connections):
    connections_count = context.num_connections('/deepstream')
    assert connections_count == int(num_connections), (str(connections_count) +
                                                       " active connections.")


@then(u'the second server has {num_connections} active connections')
def second_server_num_connections(context, num_connections):
    connections_count = context.num_connections('/deepstream2')
    assert connections_count == int(num_connections), (str(connections_count) +
                                                       " active connections.")


@then(u'the last message the server recieved is {message}')
def server_last_message(context, message):
    expected = message.replace("|", chr(31)).replace("+", chr(30))
    expected = expected.replace("<FIRST_SERVER_URL>", config.FIRST_SERVER_URL)
    parsed_expected = message_parser.parse(expected, context.client)[0]

    if context.client._connection._url == config.FIRST_SERVER_URL:
        messages = context.received_messages('/deepstream')
    else:
        messages = context.received_messages('/deepstream2')

    while True:
        if messages:

            parsed_actual = message_parser.parse(