<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_plugz
----------------------------------

Tests for `plugz` module.
"""
import os

import pytest

import plugz
from plugz import errors, PluginTypeBase, StandardPluginType

def test_loading_plugins_without_correct_arguments():
    """ Loading Plugins without giving valid arguments should fail.

    Make sure this is actually the case by going through different
    scenarios regarding invalid plugin types.

    """
    # if None is passed as type, the according error needs to be raised
    with pytest.raises(errors.NoValidPluginTypeError):
        plugins = plugz.load_plugins([], None)

    # create class object that is not a valid type
    # because it does not inherit from the correct class
    class MyInvalidType():
        pass

    # if an invalid PluginType is given, the according error is raised
    with pytest.raises(errors.InvalidPluginTypeError):
        plugins = plugz.load_plugins([], MyInvalidType)

    class MyValidType(PluginTypeBase):
        pass

    # if no paths are given, raise the according error
    with pytest.raises(errors.NoPluginPathsProvided):
        plugins = plugz.load_plugins([], MyValidType)

    # if paths are given but one is invalid, raise the error
    with pytest.raises(errors.InvalidPluginPath):
        plugins = plugz.load_plugins(['/invalid/path/' ], MyValidType)


def test_loading_plugins_for_standard_plugin_type():
    """    """
    rel_path_tokens = ['data', 'plugins', 'standard', 'valid']
    valid_dir = os.path.join(os.path.dirname(__file__), *rel_path_tokens)
    plugins = plugz.load_plugins([valid_dir], StandardPluginType)

    assert len(plugins) == 2, \
           'Test did not find the two valid plugins in data. Found %s' % plugins

    # make sure the loaded plugins have the correct plugintype.
    assert all(map(lambda x: x.plugintype == StandardPluginType.plugintype, plugins))
    # make sure it's the correct plugins that were loaded.
    assert 'MyValidPluginOne' in [p.__name__ for p in plugins]
    assert 'MyValidPluginTwo' in [p.__name__ for p in plugins]

    for p in plugins:
        instance = p()
        instance.activate()
        # print 'Activated:', instance
<commit_msg>rename the plugin. that was done to make the docs nicer as that plugin is included in the docs.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_plugz
----------------------------------

Tests for `plugz` module.
"""
import os

import pytest

import plugz
from plugz import errors, PluginTypeBase, StandardPluginType

def test_loading_plugins_without_correct_arguments():
    """ Loading Plugins without giving valid arguments should fail.

    Make sure this is actually the case by going through different
    scenarios regarding invalid plugin types.

    """
    # if None is passed as type, the according error needs to be raised
    with pytest.raises(errors.NoValidPluginTypeError):
        plugins = plugz.load_plugins([], None)

    # create class object that is not a valid type
    # because it does not inherit from the correct class
    class MyInvalidType():
        pass

    # if an invalid PluginType is given, the according error is raised
    with pytest.raises(errors.InvalidPluginTypeError):
        plugins = plugz.load_plugins([], MyInvalidType)

    class MyValidType(PluginTypeBase):
        pass

    # if no paths are given, raise the according error
    with pytest.raises(errors.NoPluginPathsProvided):
        plugins = plugz.load_plugins([], MyValidType)

    # if paths are given but one is invalid, raise the error
    with pytest.raises(errors.InvalidPluginPath):
        plugins = plugz.load_plugins(['/invalid/path/' ], MyValidType)


def test_loading_plugins_for_standard_plugin_type():
    """    """
    rel_path_tokens = ['data', 'plugins', 'standard', 'valid']
    valid_dir = os.path.join(os.path.dirname(__file__), *rel_path_tokens)
    plugins = plugz.load_plugins([valid_dir], StandardPluginType)

    assert len(plugins) == 2, \
           'Test did not find the two valid plugins in data. Found %s' % plugins

    # make sure the loaded plugins have the correct plugintype.
    assert all(map(lambda x: x.plugintype == StandardPluginType.plugintype, plugins))
    # make sure it's the correct plugins that were loaded.
    assert 'MyFirstValidPlugin' in [p.__name__ for p in plugins]
    assert 'MyValidPluginTwo' in [p.__name__ for p in plugins]

    for p in plugins:
        instance = p()
        instance.activate()
        # print 'Activated:', instance

{'fraction_non_alphanumeric': 0.10153172866520788, 'fraction_numerical': 0.00087527352297593, 'mean_word_length': 3.2206832871652815, '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': '726023', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1252, 'n_words': 446}