<commit_before>#!/usr/bin/env python
"""
Send a message and confirm you can retrieve it with Basic.Get
Test Steps:

1) Connect to broker    - start_test
2) Open Channel         - on_connected
3) Delcare Queue        - on_channel_open
4) Send test message    - on_queue_declared
5) Call basic get       - on_queue_declared
6) Validate that sent message and basic get body are the same - check_message
"""
import utils.async as async
import nose
from pika.adapters import SelectConnection

channel = None
confirmed = False
connection = None
queue = None

ADAPTER = SelectConnection
HOST = 'localhost'
PORT = 5672


@nose.tools.timed(2)
def start_test():
    global confirmed, connection
    confirmed = False
    connection = async.connect(ADAPTER, HOST, PORT, on_connected)
    connection.ioloop.start()
    if not confirmed:
        assert False, 'Messages did not match.'
    pass


@nose.tools.nottest
def on_connected(connection):
    global connected
    connected = connection.is_open
    if connected:
        async.channel(connection, on_channel_open)


@nose.tools.nottest
def on_channel_open(channel_):
    global channel, queue
    channel = channel_
    queue = async.queue_name()
    async.queue_declare(channel, queue, on_queue_declared)


@nose.tools.nottest
def on_queue_declared(frame):
    global channel, queue

    test_message = async.send_test_message(channel, queue)

    def check_message(channel_number, method, header, body):
        global connection, confirmed
        confirmed = (body == test_message)
        connection.ioloop.stop()

    channel.basic_get(callback=check_message, queue=queue)
<commit_msg>Move to class based test<commit_after>#!/usr/bin/env python
"""
Send a message and confirm you can retrieve it with Basic.Get
Test Steps:

1) Connect to broker    - start_test
2) Open Channel         - on_connected
3) Delcare Queue        - on_channel_open
4) Send test message    - on_queue_declared
5) Call basic get       - on_queue_declared
6) Validate that sent message and basic get body are the same - check_message
"""
import utils.async as async
import nose
from pika.adapters import SelectConnection

channel = None
confirmed = False
connection = None
queue = None

ADAPTER = SelectConnection
HOST = 'localhost'
PORT = 5672

class TestAsyncSendGet(object):

    def __init__(self):
        self.confirmed = False
        self.queue = async.queue_name()

    @nose.tools.timed(2)
    def test_send_and_get(self):
        self.connection = async.connect(ADAPTER, HOST, PORT,
                                        self._on_connected)
        self.connection.ioloop.start()
        if not self.confirmed:
            assert False, 'Messages did not match.'
        pass

    def _on_connected(self, connection):
        async.channel(self.connection, self._on_channel_open)

    def _on_channel_open(self, channel):
        self.channel = channel
        async.queue_declare(self.channel, self.queue, self.on_queue_declared)

    def on_queue_declared(self, frame):
        test_message = async.send_test_message(self.channel, self.queue)
        def check_message(channel_number, method, header, body):
            self.confirmed = (body == test_message)
            self.connection.ioloop.stop()
        self.channel.basic_get(callback=check_message, queue=self.queue)

{'fraction_non_alphanumeric': 0.08114630467571644, 'fraction_numerical': 0.006636500754147813, 'mean_word_length': 3.229591836734694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4012706', 'n_tokens_mistral': 985, 'n_tokens_neox': 948, 'n_words': 282}