<commit_before>import subprocess
try:
    import unittest2 as unittest
except ImportError:
    import unittest

import rabbitpy


class TestBasicPublishing(unittest.TestCase):

    INPUT = ['CODE SIGNING: cs_invalid_page(0x10fa17000): p=85310[python]',
             'CODE SIGNING: cs_invalid_page(0x1061ca000): p=85314[python]']

    def setUp(self):
        self.connection = rabbitpy.Connection()
        self.channel = self.connection.channel()
        self.queue = rabbitpy.Queue(self.channel,
                                    exclusive=True,
                                    auto_delete=True)
        self.queue.declare()

    def test_publishing_messages(self):
        cmd = ['python', 'rabbitstew.py', '-r', self.queue.name]
        process = subprocess.Popen(cmd, stdin=subprocess.PIPE)
        process.communicate(input='\n'.join(self.INPUT) + '\n')
        process.wait()
        self.assertEqual(0, process.returncode)
        msg = self.queue.get(False)
        if not msg:
            assert False, 'Message not retrieved from queue'
        self.assertEqual(msg.body, self.INPUT[0])
        msg = self.queue.get(False)<commit_msg>Try and fix the test in Python3<commit_after>import io
import subprocess
try:
    import unittest2 as unittest
except ImportError:
    import unittest

import rabbitpy


class TestBasicPublishing(unittest.TestCase):

    INPUT = ['CODE SIGNING: cs_invalid_page(0x10fa17000): p=85310[python]',
             'CODE SIGNING: cs_invalid_page(0x1061ca000): p=85314[python]']

    def setUp(self):
        self.connection = rabbitpy.Connection()
        self.channel = self.connection.channel()
        self.queue = rabbitpy.Queue(self.channel,
                                    exclusive=True,
                                    auto_delete=True)
        self.queue.declare()

    def test_publishing_messages(self):
        cmd = ['python', 'rabbitstew.py', '-r', self.queue.name]
        input = b'\n'.join(self.INPUT) + b'\n'
        process = subprocess.Popen(cmd, stdin=subprocess.PIPE)
        process.communicate(input=input)
        process.wait()
        self.assertEqual(0, process.returncode)
        msg = self.queue.get(False)
        if not msg:
            assert False, 'Message not retrieved from queue'
        self.assertEqual(msg.body, self.INPUT[0])
        msg = self.queue.get(False)
{'fraction_non_alphanumeric': 0.110875106202209, 'fraction_numerical': 0.02506372132540357, 'mean_word_length': 2.432944606413994, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '544896', 'n_tokens_mistral': 747, 'n_tokens_neox': 691, 'n_words': 141}