From 50e8fef125341dc529f770dc7a6f48783c66a89e Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Thu, 21 Jan 2016 08:26:05 -0600 Subject: [PATCH] Add more PluginManager tests --- tests/unit/test_plugin_manager.py | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/unit/test_plugin_manager.py b/tests/unit/test_plugin_manager.py index 8bafd2b..022848f 100644 --- a/tests/unit/test_plugin_manager.py +++ b/tests/unit/test_plugin_manager.py @@ -4,6 +4,13 @@ import mock 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('pkg_resources.iter_entry_points') def test_calls_pkg_resources_on_instantiation(iter_entry_points): """Verify that we call iter_entry_points when we create a manager.""" @@ -11,3 +18,45 @@ def test_calls_pkg_resources_on_instantiation(iter_entry_points): manager.PluginManager(namespace='testing.pkg_resources') iter_entry_points.assert_called_once_with('testing.pkg_resources') + + +@mock.patch('pkg_resources.iter_entry_points') +def test_calls_pkg_resources_creates_plugins_automaticaly(iter_entry_points): + """Verify that we create Plugins on instantiation.""" + iter_entry_points.return_value = [ + create_entry_point_mock('T100'), + create_entry_point_mock('T200'), + ] + plugin_mgr = manager.PluginManager(namespace='testing.pkg_resources') + + iter_entry_points.assert_called_once_with('testing.pkg_resources') + 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('pkg_resources.iter_entry_points') +def test_proxies_contains_to_plugins_dictionary(iter_entry_points): + """Verify that we can use the PluginManager like a dictionary.""" + iter_entry_points.return_value = [ + create_entry_point_mock('T100'), + create_entry_point_mock('T200'), + ] + plugin_mgr = manager.PluginManager(namespace='testing.pkg_resources') + + assert 'T100' in plugin_mgr + assert 'T200' in plugin_mgr + + +@mock.patch('pkg_resources.iter_entry_points') +def test_proxies_getitm_to_plugins_dictionary(iter_entry_points): + """Verify that we can use the PluginManager like a dictionary.""" + iter_entry_points.return_value = [ + create_entry_point_mock('T100'), + create_entry_point_mock('T200'), + ] + plugin_mgr = manager.PluginManager(namespace='testing.pkg_resources') + + assert isinstance(plugin_mgr['T100'], manager.Plugin) + assert isinstance(plugin_mgr['T200'], manager.Plugin)