How to use the flake8.plugins.manager.Plugin function in flake8

To help you get started, we’ve selected a few flake8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PyCQA / flake8 / tests / unit / test_utils.py View on Github external
def test_parameters_for_function_plugin():
    """Verify that we retrieve the parameters for a function plugin."""
    def fake_plugin(physical_line, self, tree, optional=None):
        pass

    plugin = plugin_manager.Plugin('plugin-name', object())
    plugin._plugin = fake_plugin
    assert utils.parameters_for(plugin) == {
        'physical_line': True,
        'self': True,
        'tree': True,
        'optional': False,
    }
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_load_plugin_is_idempotent():
    """Verify we use the preferred methods on new versions of setuptools."""
    entry_point = mock.Mock(spec=['load'])
    plugin = manager.Plugin('T000', entry_point)

    plugin.load_plugin()
    plugin.load_plugin()
    plugin.load_plugin()
    entry_point.load.assert_called_once_with()
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_provide_options():
    """Verify we call add_options on the plugin only if it exists."""
    # Set up our mocks and Plugin object
    entry_point = mock.Mock(spec=['load'])
    plugin_obj = mock.Mock(spec_set=['name', 'version', 'add_options',
                                     'parse_options'])
    option_values = optparse.Values({'enable_extensions': []})
    option_manager = mock.Mock()
    plugin = manager.Plugin('T000', entry_point)
    plugin._plugin = plugin_obj

    # Call the method we're testing.
    plugin.provide_options(option_manager, option_values, None)

    # Assert that we call add_options
    plugin_obj.parse_options.assert_called_once_with(
        option_manager, option_values, None
    )
github PyCQA / flake8 / tests / unit / test_plugin_manager.py View on Github external
def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck):
    """Verify that we create Plugins on instantiation."""
    entry_points_mck.return_value = {
        'testing.entrypoints': [
            importlib_metadata.EntryPoint('T100', '', None),
            importlib_metadata.EntryPoint('T200', '', None),
        ],
    }
    plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')

    entry_points_mck.assert_called_once_with()
    assert 'T100' in plugin_mgr.plugins
    assert 'T200' in plugin_mgr.plugins
    assert isinstance(plugin_mgr.plugins['T100'], manager.Plugin)
    assert isinstance(plugin_mgr.plugins['T200'], manager.Plugin)
github PyCQA / flake8 / tests / unit / test_plugin_manager.py View on Github external
def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck):
    """Verify that we create Plugins on instantiation."""
    entry_points_mck.return_value = {
        'testing.entrypoints': [
            importlib_metadata.EntryPoint('T100', '', None),
            importlib_metadata.EntryPoint('T200', '', None),
        ],
    }
    plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')

    entry_points_mck.assert_called_once_with()
    assert 'T100' in plugin_mgr.plugins
    assert 'T200' in plugin_mgr.plugins
    assert isinstance(plugin_mgr.plugins['T100'], manager.Plugin)
    assert isinstance(plugin_mgr.plugins['T200'], manager.Plugin)
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_plugin_property_loads_plugin_on_first_use():
    """Verify that we load our plugin when we first try to use it."""
    entry_point = mock.Mock(spec=['load'])
    plugin = manager.Plugin('T000', entry_point)

    assert plugin.plugin is not None
    entry_point.load.assert_called_once_with()
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_enable(ignore_list, code, expected_list):
    """Verify that enabling a plugin removes it from the ignore list."""
    options = mock.Mock(ignore=ignore_list)
    optmanager = mock.Mock()
    plugin = manager.Plugin(code, mock.Mock())

    plugin.enable(optmanager, options)

    assert options.ignore == expected_list
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_register_options():
    """Verify we call add_options on the plugin only if it exists."""
    # Set up our mocks and Plugin object
    entry_point = mock.Mock(spec=['load'])
    plugin_obj = mock.Mock(spec_set=['name', 'version', 'add_options',
                                     'parse_options'])
    option_manager = mock.Mock(spec=['register_plugin'])
    plugin = manager.Plugin('T000', entry_point)
    plugin._plugin = plugin_obj

    # Call the method we're testing.
    plugin.register_options(option_manager)

    # Assert that we call add_options
    plugin_obj.add_options.assert_called_once_with(option_manager)
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_load_noncallable_plugin():
    """Verify that we do not load a non-callable plugin."""
    entry_point = mock.Mock(spec=['load'])
    entry_point.load.return_value = mock.NonCallableMock()
    plugin = manager.Plugin('T000', entry_point)

    with pytest.raises(exceptions.FailedToLoadPlugin):
        plugin.load_plugin()
    entry_point.load.assert_called_once_with()
github PyCQA / flake8 / tests / unit / test_plugin.py View on Github external
def test_execute_calls_plugin_with_passed_arguments():
    """Verify that we pass arguments directly to the plugin."""
    entry_point = mock.Mock(spec=['load'])
    plugin_obj = mock.Mock()
    plugin = manager.Plugin('T000', entry_point)
    plugin._plugin = plugin_obj

    plugin.execute('arg1', 'arg2', kwarg1='value1', kwarg2='value2')
    plugin_obj.assert_called_once_with(
        'arg1', 'arg2', kwarg1='value1', kwarg2='value2'
    )

    # Extra assertions
    assert entry_point.load.called is False