diff options
| author | Anthony Sottile <asottile@umich.edu> | 2019-11-28 17:30:52 -0800 |
|---|---|---|
| committer | Anthony Sottile <asottile@umich.edu> | 2019-11-28 17:30:52 -0800 |
| commit | d3c95f00d0ac14adcceb423173ff7106aa42d116 (patch) | |
| tree | b38f7fe434ac2adffaf171a92b0c13082af0f0d9 /tests/unit | |
| parent | 15de413f9e04a9fe360d6a22a66ba163d21a7cf4 (diff) | |
| download | flake8-d3c95f00d0ac14adcceb423173ff7106aa42d116.tar.gz | |
Switch from entrypoints to importlib_metadata
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/test_debug.py | 8 | ||||
| -rw-r--r-- | tests/unit/test_exceptions.py | 8 | ||||
| -rw-r--r-- | tests/unit/test_plugin_manager.py | 58 | ||||
| -rw-r--r-- | tests/unit/test_plugin_type_manager.py | 2 |
4 files changed, 31 insertions, 45 deletions
diff --git a/tests/unit/test_debug.py b/tests/unit/test_debug.py index c973abb..6398cf9 100644 --- a/tests/unit/test_debug.py +++ b/tests/unit/test_debug.py @@ -1,5 +1,4 @@ """Tests for our debugging module.""" -import entrypoints import mock import pytest @@ -9,9 +8,7 @@ from flake8.options import manager def test_dependencies(): """Verify that we format our dependencies appropriately.""" - expected = [{'dependency': 'entrypoints', - 'version': entrypoints.__version__}] - assert expected == debug.dependencies() + assert [] == debug.dependencies() @pytest.mark.parametrize('plugins, expected', [ @@ -46,8 +43,7 @@ def test_information(system, pyversion, pyimpl): 'is_local': False}, {'plugin': 'pycodestyle', 'version': '2.0.0', 'is_local': False}], - 'dependencies': [{'dependency': 'entrypoints', - 'version': entrypoints.__version__}], + 'dependencies': [], 'platform': { 'python_implementation': 'CPython', 'python_version': '3.5.3', diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index 4766b78..0254cb2 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -1,10 +1,7 @@ """Tests for the flake8.exceptions module.""" import pickle -import entrypoints - from flake8 import exceptions -from flake8.plugins import manager as plugins_manager class _ExceptionTest: @@ -22,10 +19,7 @@ class TestFailedToLoadPlugin(_ExceptionTest): """Tests for the FailedToLoadPlugin exception.""" err = exceptions.FailedToLoadPlugin( - plugin=plugins_manager.Plugin( - 'plugin_name', - entrypoints.EntryPoint('plugin_name', 'os.path', None), - ), + plugin_name='plugin_name', exception=ValueError('boom!'), ) diff --git a/tests/unit/test_plugin_manager.py b/tests/unit/test_plugin_manager.py index 72959b0..9ad6aba 100644 --- a/tests/unit/test_plugin_manager.py +++ b/tests/unit/test_plugin_manager.py @@ -1,62 +1,58 @@ """Tests for flake8.plugins.manager.PluginManager.""" import mock +from flake8._compat import importlib_metadata from flake8.plugins import manager -def create_entry_point_mock(name): - """Create a mocked EntryPoint.""" - ep = mock.Mock(spec=['name']) - ep.name = name - return ep - - -@mock.patch('entrypoints.get_group_all') -def test_calls_entrypoints_on_instantiation(get_group_all): - """Verify that we call get_group_all when we create a manager.""" - get_group_all.return_value = [] +@mock.patch.object(importlib_metadata, 'entry_points') +def test_calls_entrypoints_on_instantiation(entry_points_mck): + """Verify that we call entry_points() when we create a manager.""" + entry_points_mck.return_value = {} manager.PluginManager(namespace='testing.entrypoints') - - get_group_all.assert_called_once_with('testing.entrypoints') + entry_points_mck.assert_called_once_with() -@mock.patch('entrypoints.get_group_all') -def test_calls_entrypoints_creates_plugins_automaticaly(get_group_all): +@mock.patch.object(importlib_metadata, 'entry_points') +def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck): """Verify that we create Plugins on instantiation.""" - get_group_all.return_value = [ - create_entry_point_mock('T100'), - create_entry_point_mock('T200'), - ] + entry_points_mck.return_value = { + 'testing.entrypoints': [ + importlib_metadata.EntryPoint('T100', '', None), + importlib_metadata.EntryPoint('T200', '', None), + ], + } plugin_mgr = manager.PluginManager(namespace='testing.entrypoints') - get_group_all.assert_called_once_with('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) -@mock.patch('entrypoints.get_group_all') -def test_handles_mapping_functions_across_plugins(get_group_all): +@mock.patch.object(importlib_metadata, 'entry_points') +def test_handles_mapping_functions_across_plugins(entry_points_mck): """Verify we can use the PluginManager call functions on all plugins.""" - entry_point_mocks = [ - create_entry_point_mock('T100'), - create_entry_point_mock('T200'), - ] - get_group_all.return_value = entry_point_mocks + entry_points_mck.return_value = { + 'testing.entrypoints': [ + importlib_metadata.EntryPoint('T100', '', None), + importlib_metadata.EntryPoint('T200', '', None), + ], + } plugin_mgr = manager.PluginManager(namespace='testing.entrypoints') plugins = [plugin_mgr.plugins[name] for name in plugin_mgr.names] assert list(plugin_mgr.map(lambda x: x)) == plugins -@mock.patch('entrypoints.get_group_all') -def test_local_plugins(get_group_all): +@mock.patch.object(importlib_metadata, 'entry_points') +def test_local_plugins(entry_points_mck): """Verify PluginManager can load given local plugins.""" - get_group_all.return_value = [] + entry_points_mck.return_value = {} plugin_mgr = manager.PluginManager( namespace='testing.entrypoints', local_plugins=['X = path.to:Plugin'] ) - assert plugin_mgr.plugins['X'].entry_point.module_name == 'path.to' + assert plugin_mgr.plugins['X'].entry_point.value == 'path.to:Plugin' diff --git a/tests/unit/test_plugin_type_manager.py b/tests/unit/test_plugin_type_manager.py index 4174c58..939aa8c 100644 --- a/tests/unit/test_plugin_type_manager.py +++ b/tests/unit/test_plugin_type_manager.py @@ -13,7 +13,7 @@ def create_plugin_mock(raise_exception=False): plugin = mock.create_autospec(manager.Plugin, instance=True) if raise_exception: plugin.load_plugin.side_effect = exceptions.FailedToLoadPlugin( - plugin=mock.Mock(name='T101'), + plugin_name='T101', exception=ValueError('Test failure'), ) return plugin |
