예제 #1
0
def test_get_plugin(mock_manager):
    assert mock_manager.get_plugin('plugins/test.py') is None
    assert mock_manager.find_plugin('test') is None

    from cloudbot.plugin import Plugin

    file_path = Path('plugins').resolve() / 'test.py'
    file_name = file_path.name

    obj = Plugin(
        str(file_path),
        file_name,
        'test',
        MockModule(),
    )

    mock_manager._add_plugin(obj)

    assert mock_manager.get_plugin('plugins/test.py') is obj
    assert mock_manager.find_plugin('test') is obj

    mock_manager._rem_plugin(obj)

    assert mock_manager.get_plugin('plugins/test.py') is None
    assert mock_manager.find_plugin('test') is None
예제 #2
0
def make_plugin():
    plugin_dir = Path("plugins").resolve()
    file_path = plugin_dir / "test.py"
    file_name = file_path.name
    return Plugin(
        str(file_path),
        file_name,
        "test",
        MockModule(),
    )
예제 #3
0
def make_plugin():
    plugin_dir = Path('plugins').resolve()
    file_path = plugin_dir / 'test.py'
    file_name = file_path.name
    return Plugin(
        str(file_path),
        file_name,
        'test',
        MockModule(),
    )
예제 #4
0
def load_plugin(plugin_path):
    path = Path(plugin_path)
    file_path = path.resolve()
    file_name = file_path.name
    # Resolve the path relative to the current directory
    plugin_path = file_path.relative_to(Path().resolve())
    title = ".".join(plugin_path.parts[1:]).rsplit(".", 1)[0]

    module_name = "plugins.{}".format(title)

    plugin_module = importlib.import_module(module_name)

    return Plugin(str(file_path), file_name, title, plugin_module)