<commit_before># Copyright (c) 2014, Facebook, Inc.  All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
from .base import MultiTaskTestCase, Skip

try:
    import thrift
except ImportError:
    raise Skip("thrift is required to run this test")

from sparts.tasks.fb303 import FB303ProcessorTask
from sparts.tasks.thrift import NBServerTask

from sparts.thrift import ThriftClient
from sparts.gen.fb303 import FacebookService
from sparts.gen.fb303.ttypes import fb_status

import socket

class TestFB303(MultiTaskTestCase):
    TASKS = [NBServerTask, FB303ProcessorTask]

    def assertCanConnect(self, host, port):
        s = socket.socket()
        s.settimeout(3.0)
        s.connect((host, port))
        return s

    def testNBServerConnect(self):
        server = self.service.requireTask(NBServerTask)
        self.assertNotNone(server.bound_port)
        self.assertCanConnect('127.0.0.1', server.bound_port)
        return server

    def testNBServerCommand(self):
        server = self.service.requireTask(NBServerTask)
        client = ThriftClient.for_localhost(
                server.bound_port, module=FacebookService)
        self.assertEquals(client.getStatus(), fb_status.ALIVE)
<commit_msg>py3k unittest compatibility re: PEP-420<commit_after># Copyright (c) 2014, Facebook, Inc.  All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
#
from .base import MultiTaskTestCase, Skip

try:
    import thrift.server
except ImportError:
    raise Skip("thrift is required to run this test")

from sparts.tasks.fb303 import FB303ProcessorTask
from sparts.tasks.thrift import NBServerTask

from sparts.thrift import ThriftClient
from sparts.gen.fb303 import FacebookService
from sparts.gen.fb303.ttypes import fb_status

import socket

class TestFB303(MultiTaskTestCase):
    TASKS = [NBServerTask, FB303ProcessorTask]

    def assertCanConnect(self, host, port):
        s = socket.socket()
        s.settimeout(3.0)
        s.connect((host, port))
        return s

    def testNBServerConnect(self):
        server = self.service.requireTask(NBServerTask)
        self.assertNotNone(server.bound_port)
        self.assertCanConnect('127.0.0.1', server.bound_port)
        return server

    def testNBServerCommand(self):
        server = self.service.requireTask(NBServerTask)
        client = ThriftClient.for_localhost(
                server.bound_port, module=FacebookService)
        self.assertEquals(client.getStatus(), fb_status.ALIVE)

{'fraction_non_alphanumeric': 0.07606028741675429, 'fraction_numerical': 0.022432527164388365, 'mean_word_length': 3.6106623586429727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2715728', 'n_tokens_mistral': 870, 'n_tokens_neox': 815, 'n_words': 250}