<commit_before>from ..plugin_registry import PluginRegistry


class RegistryTest(PluginRegistry):
    pass


def test_plugin_registry():
    plugins = RegistryTest()

    assert plugins.names() == []
    assert plugins.active == ''
    assert plugins.get() is None
    assert repr(plugins) == "RegistryTest(active='', registered=[])"

    plugins.register('new_plugin', lambda x: x ** 2)
    assert plugins.names() == ['new_plugin']
    assert plugins.active == ''
    assert plugins.get() is None
    assert repr(plugins) == ("RegistryTest(active='', "
                             "registered=['new_plugin'])")

    plugins.enable('new_plugin')
    assert plugins.names() == ['new_plugin']
    assert plugins.active == 'new_plugin'
    assert plugins.get()(3) == 9
    assert repr(plugins) == ("RegistryTest(active='new_plugin', "
                             "registered=['new_plugin'])")
<commit_msg>TST: add test of plugin registry options<commit_after>from ..plugin_registry import PluginRegistry
from typing import Callable


class TypedCallableRegistry(PluginRegistry[Callable[[int], int]]):
    pass


class GeneralCallableRegistry(PluginRegistry):
    pass


def test_plugin_registry():
    plugins = TypedCallableRegistry()

    assert plugins.names() == []
    assert plugins.active == ''
    assert plugins.get() is None
    assert repr(plugins) == "TypedCallableRegistry(active='', registered=[])"

    plugins.register('new_plugin', lambda x: x ** 2)
    assert plugins.names() == ['new_plugin']
    assert plugins.active == ''
    assert plugins.get() is None
    assert repr(plugins) == ("TypedCallableRegistry(active='', "
                             "registered=['new_plugin'])")

    plugins.enable('new_plugin')
    assert plugins.names() == ['new_plugin']
    assert plugins.active == 'new_plugin'
    assert plugins.get()(3) == 9
    assert repr(plugins) == ("TypedCallableRegistry(active='new_plugin', "
                             "registered=['new_plugin'])")


def test_plugin_registry_extra_options():
    plugins = GeneralCallableRegistry()

    plugins.register('metadata_plugin', lambda x, p=2: x ** p)
    plugins.enable('metadata_plugin')
    assert plugins.get()(3) == 9

    plugins.enable('metadata_plugin', p=3)
    assert plugins.get()(3) == 27

{'fraction_non_alphanumeric': 0.14442013129102846, 'fraction_numerical': 0.0056892778993435445, 'mean_word_length': 3.5267326732673268, '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': '1202920', 'n_tokens_mistral': 661, 'n_tokens_neox': 628, 'n_words': 143}