<commit_before>import socket
from unittest import mock

import pytest

from aiologstash import create_tcp_handler

pytestmark = pytest.mark.asyncio


async def test_simple(setup_logger, loop):
    log, srv = await setup_logger()
    log.info('Info %s', 'text')
    await srv.wait()
    js = srv.jsons
    assert js[0] == {
        "@timestamp": mock.ANY,
        "@version": "1",
        "message": "Info text",
        "host": socket.gethostname(),
        "path": __file__,
        "tags": [],
        "type": "Logstash",
        "level": "INFO",
        "logger_name": "aiologstash_test",
        "stack_info": None}


async def test_cannot_connect(unused_tcp_port, loop):
    with pytest.raises(OSError):
        await create_tcp_handler('127.0.0.1', unused_tcp_port, loop=loop)<commit_msg>Test implicit loop (#3)<commit_after>import socket
from unittest import mock

import pytest

from aiologstash import create_tcp_handler

pytestmark = pytest.mark.asyncio


async def test_simple(setup_logger, loop):
    log, srv = await setup_logger()
    log.info('Info %s', 'text')
    await srv.wait()
    js = srv.jsons
    assert js[0] == {
        "@timestamp": mock.ANY,
        "@version": "1",
        "message": "Info text",
        "host": socket.gethostname(),
        "path": __file__,
        "tags": [],
        "type": "Logstash",
        "level": "INFO",
        "logger_name": "aiologstash_test",
        "stack_info": None}


async def test_cannot_connect(unused_tcp_port, loop):
    with pytest.raises(OSError):
        await create_tcp_handler('127.0.0.1', unused_tcp_port, loop=loop)


async def test_implicit_loop(make_tcp_server, loop):
    server = await make_tcp_server()
    try:
        handler = await create_tcp_handler('127.0.0.1', server.port)
        assert handler._loop is loop
    finally:
        handler.close()
        await handler.wait_closed()
{'fraction_non_alphanumeric': 0.13152289669861555, 'fraction_numerical': 0.012247071352502662, 'mean_word_length': 2.989384288747346, 'pattern_counts': {'":': 20, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '1317109', 'n_tokens_mistral': 630, 'n_tokens_neox': 633, 'n_words': 144}