summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-02-02 16:53:24 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2016-02-02 16:53:24 -0600
commit0645ec3ef771c8e2e6ef39bdd5eb360067d147b9 (patch)
tree2c63c48e47bdaa5429d8028b4671557dea895300 /tests
parent91327c75e0da54fb7f4479499009fb6946f59820 (diff)
downloadflake8-0645ec3ef771c8e2e6ef39bdd5eb360067d147b9.tar.gz
Move __contains__ and __getitem__ to proper class
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_plugin_manager.py28
-rw-r--r--tests/unit/test_plugin_type_manager.py33
2 files changed, 34 insertions, 27 deletions
diff --git a/tests/unit/test_plugin_manager.py b/tests/unit/test_plugin_manager.py
index 05073cf..8991b96 100644
--- a/tests/unit/test_plugin_manager.py
+++ b/tests/unit/test_plugin_manager.py
@@ -37,32 +37,6 @@ def test_calls_pkg_resources_creates_plugins_automaticaly(iter_entry_points):
@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_getitem_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)
-
-
-@mock.patch('pkg_resources.iter_entry_points')
def test_handles_mapping_functions_across_plugins(iter_entry_points):
"""Verify we can use the PluginManager call functions on all plugins."""
entry_point_mocks = [
@@ -71,6 +45,6 @@ def test_handles_mapping_functions_across_plugins(iter_entry_points):
]
iter_entry_points.return_value = entry_point_mocks
plugin_mgr = manager.PluginManager(namespace='testing.pkg_resources')
- plugins = [plugin_mgr[name] for name in plugin_mgr.names]
+ plugins = [plugin_mgr.plugins[name] for name in plugin_mgr.names]
assert list(plugin_mgr.map(lambda x: x)) == plugins
diff --git a/tests/unit/test_plugin_type_manager.py b/tests/unit/test_plugin_type_manager.py
index 2735dec..36fb92a 100644
--- a/tests/unit/test_plugin_type_manager.py
+++ b/tests/unit/test_plugin_type_manager.py
@@ -35,6 +35,13 @@ def create_mapping_manager_mock(plugins):
return manager_mock
+def create_manager_with_plugins(plugins):
+ """Create a fake PluginManager with a plugins dictionary."""
+ manager_mock = mock.create_autospec(manager.PluginManager)
+ manager_mock.plugins = plugins
+ return manager_mock
+
+
class TestType(manager.PluginTypeManager):
"""Fake PluginTypeManager."""
@@ -167,6 +174,32 @@ def test_provide_options(PluginManager):
extra_args)
+@mock.patch('flake8.plugins.manager.PluginManager')
+def test_proxy_contains_to_managers_plugins_dict(PluginManager):
+ """Verify that we proxy __contains__ to the manager's dictionary."""
+ plugins = {'T10%i' % i: create_plugin_mock() for i in range(8)}
+ # Return our PluginManager mock
+ PluginManager.return_value = create_manager_with_plugins(plugins)
+
+ type_mgr = TestType()
+ for i in range(8):
+ key = 'T10%i' % i
+ assert key in type_mgr
+
+
+@mock.patch('flake8.plugins.manager.PluginManager')
+def test_proxies_getitem_to_managers_plugins_dictionary(PluginManager):
+ """Verify that we can use the PluginTypeManager like a dictionary."""
+ plugins = {'T10%i' % i: create_plugin_mock() for i in range(8)}
+ # Return our PluginManager mock
+ PluginManager.return_value = create_manager_with_plugins(plugins)
+
+ type_mgr = TestType()
+ for i in range(8):
+ key = 'T10%i' % i
+ assert type_mgr[key] is plugins[key]
+
+
class FakePluginTypeManager(manager.NotifierBuilder):
"""Provide an easy way to test the NotifierBuilder."""