Add more PluginManager tests

This commit is contained in:
Ian Cordasco 2016-01-21 08:26:05 -06:00
parent 6a72e36681
commit 50e8fef125

View file

@ -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)