<commit_before>from munch import Munch

import gossip
import gossip.groups
import pytest
from gossip.exception_policy import Inherit

from .conftest import RegisteredHook


def test_exception_from_internal_hook(registered_hook):
    registered_hook.fail_when_called()
    called = Munch(count=0)

    @gossip.register("gossip.on_handler_exception")
    def handle_exception(handler, exception, hook):  # pylint: disable=unused-variable, unused-argument
        called.count += 1
        raise CustomException()

    with pytest.raises(CustomException):
        registered_hook.trigger()

    assert called.count == 1


class CustomException(Exception):
    pass


def test_gossip_exception_caught_hook(registered_hook):
    registered_hook.fail_when_called()
    error = Munch(caught=False)

    @gossip.register("gossip.on_handler_exception")
    def handle_exception(handler, exception, hook):  # pylint: disable=unused-variable, unused-argument
        assert handler is registered_hook.func
        assert exception[0] is registered_hook.exception_class
        assert isinstance(exception[1], registered_hook.exception_class)
        error.caught = True

    with pytest.raises(registered_hook.exception_class):
        registered_hook.trigger()

    assert error.caught<commit_msg>Pylint fixes<commit_after># pylint: disable=unused-argument
from munch import Munch

import gossip
import gossip.groups
import pytest
from gossip.exception_policy import Inherit

from .conftest import RegisteredHook


def test_exception_from_internal_hook(registered_hook):
    registered_hook.fail_when_called()
    called = Munch(count=0)

    # pylint: disable=unused-variable
    @gossip.register("gossip.on_handler_exception")
    def handle_exception(handler, exception, hook):
        called.count += 1
        raise CustomException()

    with pytest.raises(CustomException):
        registered_hook.trigger()

    assert called.count == 1


class CustomException(Exception):
    pass


def test_gossip_exception_caught_hook(registered_hook):
    registered_hook.fail_when_called()
    error = Munch(caught=False)

    @gossip.register("gossip.on_handler_exception")
    def handle_exception(handler, exception, hook):  # pylint: disable=unused-variable, unused-argument
        assert handler is registered_hook.func
        assert exception[0] is registered_hook.exception_class
        assert isinstance(exception[1], registered_hook.exception_class)
        error.caught = True

    with pytest.raises(registered_hook.exception_class):
        registered_hook.trigger()

    assert error.caught
{'fraction_non_alphanumeric': 0.07867335133050521, 'fraction_numerical': 0.0038565368299267257, 'mean_word_length': 4.370600414078675, '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': '3809264', 'n_tokens_mistral': 759, 'n_tokens_neox': 729, 'n_words': 152}