<commit_before>import os.path
import socket
import unittest

import pants

from pants.test._pants_util import *

class FileSender(pants.Connection):
    def on_connect(self):
        with open(os.path.dirname(__file__) + "/data.txt", 'r') as test_file:
            self.write_file(test_file)

class TestSendfile(PantsTestCase):
    def setUp(self):
        self.server = pants.Server(FileSender).listen(('127.0.0.1', 4040))
        PantsTestCase.setUp(self)

    def test_sendfile(self):
        with open(os.path.dirname(__file__) + "/data.txt", 'r') as test_file:
            expected_data = ''.join(test_file.readlines())

        sock = socket.socket()
        sock.settimeout(1.0)
        sock.connect(('127.0.0.1', 4040))
        actual_data = sock.recv(1024)
        self.assertEquals(actual_data, expected_data)
        sock.close()<commit_msg>Fixed an issue with the sendfile() automated test.<commit_after>import os.path
import socket
import unittest

import pants

from pants.test._pants_util import *

class FileSender(pants.Connection):
    def on_connect(self):
        with open(os.path.dirname(__file__) + "/data.txt", 'r') as test_file:
            # The file is flushed here to get around an awkward issue
            # that was only happening with the unit test. sendfile() was
            # blocking for some strange reason.
            self.write_file(test_file, flush=True)

class TestSendfile(PantsTestCase):
    def setUp(self):
        self.server = pants.Server(FileSender).listen(('127.0.0.1', 4040))
        PantsTestCase.setUp(self)

    def test_sendfile(self):
        with open(os.path.dirname(__file__) + "/data.txt", 'r') as test_file:
            expected_data = ''.join(test_file.readlines())

        sock = socket.socket()
        sock.settimeout(1.0)
        sock.connect(('127.0.0.1', 4040))
        actual_data = sock.recv(1024)
        self.assertEquals(actual_data, expected_data)
        sock.close()
{'fraction_non_alphanumeric': 0.12345679012345678, 'fraction_numerical': 0.026748971193415638, 'mean_word_length': 2.913480885311871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2945373', 'n_tokens_mistral': 634, 'n_tokens_neox': 602, 'n_words': 133}