<commit_before>import mock
import pytest
import re

from serfclient import client


class TestSerfClientCommands(object):
    """
    Common commands for the library
    """
    @pytest.fixture
    def serf(self):
        return client.SerfClient()

    @mock.patch('serfclient.client.SerfConnection')
    def test_rpc_auth(self, mock_serf_connection_class):
        mock_serf_connection = mock.MagicMock()
        mock_serf_connection_class.return_value = mock_serf_connection
        serf = client.SerfClient(rpc_auth='secret')
        assert serf.connection is not None
        mock_serf_connection.auth.assert_called_once_with('secret')

    def test_has_a_default_host_and_port(self, serf):
        assert serf.host == 'localhost'
        assert serf.port == 7373

    def test_initialises_a_serf_connection_on_creation(self, serf):
        assert serf.connection is not None

    def test_sending_a_simple_event(self, serf):
        assert serf.event('foo', 'bar').head == {b'Error': b'', b'Seq': 1}

    def test_sending_a_non_coalescing_event(self, serf):
        assert serf.event('foo', 'bar').head == {b'Error': b'', b'Seq': 1}

    def test_event_payload_is_optional(self, serf):
        assert serf.event('foo').head == {b'Error': b'', b'Seq': 1}
        assert serf.event('bar', coalesce=False).head == \
            {b'Error': b'', b'Seq': 2}<commit_msg>Close all sockets for client tests<commit_after>import mock
import pytest
import re

from contextlib import closing
from serfclient import client


class TestSerfClientCommands(object):
    """
    Common commands for the library
    """
    @pytest.yield_fixture
    def serf(self):
        with closing(client.SerfClient()) as serf:
            yield serf

    @mock.patch('serfclient.client.SerfConnection')
    def test_rpc_auth(self, mock_serf_connection_class):
        mock_serf_connection = mock.MagicMock()
        mock_serf_connection_class.return_value = mock_serf_connection
        with closing(client.SerfClient(rpc_auth='secret')) as serf:
            assert serf.connection is not None
        mock_serf_connection.auth.assert_called_once_with('secret')

    def test_has_a_default_host_and_port(self, serf):
        assert serf.host == 'localhost'
        assert serf.port == 7373

    def test_initialises_a_serf_connection_on_creation(self, serf):
        assert serf.connection is not None

    def test_sending_a_simple_event(self, serf):
        assert serf.event('foo', 'bar').head == {b'Error': b'', b'Seq': 1}

    def test_sending_a_non_coalescing_event(self, serf):
        assert serf.event('foo', 'bar').head == {b'Error': b'', b'Seq': 1}

    def test_event_payload_is_optional(self, serf):
        assert serf.event('foo').head == {b'Error': b'', b'Seq': 1}
        assert serf.event('bar', coalesce=False).head == \
            {b'Error': b'', b'Seq': 2}
{'fraction_non_alphanumeric': 0.1180385288966725, 'fraction_numerical': 0.005604203152364273, 'mean_word_length': 3.555023923444976, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6471417', 'n_tokens_mistral': 963, 'n_tokens_neox': 931, 'n_words': 196}