Beispiel #1
0
def test_init_plugins_skip_inactive(installed_plugins, plugin_config,
                                    plugin_kwargs):
    """Skips plugins that are not activated in core config."""
    inited_names, inited_plugins, errors = plugins_loader._init_plugins(
        [conftest.REGISTERED_ACTIVE_PLUGINS[0]], installed_plugins,
        plugin_config, plugin_kwargs)

    assert 1 == len(inited_plugins) == len(inited_names)
    exp = plugin_config.get(conftest.REGISTERED_ACTIVE_PLUGINS[0])
    assert exp == inited_plugins[0].config
Beispiel #2
0
def test_init_plugins_empty_config(installed_plugins, plugin_kwargs):
    """Loads plugin if mathcing config key exists with empty config."""
    config = {name: {} for name in conftest.REGISTERED_ACTIVE_PLUGINS}

    inited_names, inited_plugins, errors = plugins_loader._init_plugins(
        conftest.REGISTERED_ACTIVE_PLUGINS, installed_plugins, config,
        plugin_kwargs)

    assert 3 == len(inited_plugins) == len(inited_names)
    for plugin_obj in inited_plugins:
        assert {} == plugin_obj.config
Beispiel #3
0
def test_init_plugins_skipped(installed_plugins, plugin_config, caplog,
                              plugin_kwargs):
    """Skips plugins that are not configured."""
    config = {'xyz.event_consumer': plugin_config['xyz.event_consumer']}

    inited_names, inited_plugins, errors = plugins_loader._init_plugins(
        conftest.REGISTERED_ACTIVE_PLUGINS, installed_plugins, config,
        plugin_kwargs)

    assert 1 == len(inited_plugins) == len(inited_names)
    assert 2 == len(caplog.records)
Beispiel #4
0
def test_init_plugins(installed_plugins, plugin_config, inited_plugins,
                      plugin_kwargs):
    """Plugins are initialized with their config."""
    inited_names, inited_plugins, errors = plugins_loader._init_plugins(
        conftest.REGISTERED_ACTIVE_PLUGINS, installed_plugins, plugin_config,
        plugin_kwargs)

    assert sorted(conftest.REGISTERED_ACTIVE_PLUGINS) == sorted(inited_names)
    for plugin_obj in inited_plugins:
        assert is_instance_of_stub(plugin_obj)
        assert any([p.config == plugin_obj.config for p in inited_plugins])
Beispiel #5
0
def test_init_plugins_exceptions(mocker, plugin_kwargs):
    """Non-callable plugin returns plugin-specific exceptions."""
    name = 'B0rkedPlugin'
    config = {'B0rkedPlugin': {'foo': 'bar'}}

    plugin_mock = mocker.MagicMock(pkg_resources.EntryPoint, autospec=True)
    plugin_mock.name = name
    plugin_mock.load.return_value = 'not_a_class'
    plugins = {name: plugin_mock}

    inited_names, inited_plugins, errors = plugins_loader._init_plugins(
        [name], plugins, config, plugin_kwargs)
    assert 1 == len(errors)