Skip to content

Commit

Permalink
Fix some tests broken by the introduction of plugin managers; Add tox…
Browse files Browse the repository at this point in the history
….ini to easily run tests on 2.6, 2.7, and 3.2
  • Loading branch information
ironfroggy committed Jul 7, 2012
1 parent 21949c9 commit b2550b1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
Welcome to straight.plugin's documentation!
===========================================

Straight Plugin is very easy.


Contents:

.. toctree::
Expand All @@ -20,7 +23,6 @@ Contents:
Overview
========

`straight.plugin` is very easy.

Loading all the classes inside a namespace which are subclasses of some
base is the preferred invocation of ``straight.plugin`` loading, and is
Expand Down
5 changes: 4 additions & 1 deletion straight/plugin/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def _post_fill(self):
plugins = self._cache
self._cache = self.load(implied_namespace)
self._post_fill()
self._cache = plugins + self._cache
combined = []
combined.extend(plugins)
combined.extend(self._cache)
self._cache = combined

This comment has been minimized.

Copy link
@hughdbrown

hughdbrown Feb 5, 2014

What was wrong with the original self._cache = plugins + self._cache? It looks like you've replaced one correct line with four equivalent lines. I think the original is clearer and more direct.


def _order(self):
self._cache.sort(key=self._plugin_priority, reverse=True)
Expand Down
6 changes: 3 additions & 3 deletions straight/plugin/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def produce(self, *args, **kwargs):
factories.
"""

new_plugin_set = PluginManager()
new_plugins = []
for p in self._plugins:
r = p(*args, **kwargs)
new_plugin_set._plugins.append(r)
return new_plugin_set
new_plugins.append(r)

This comment has been minimized.

Copy link
@hughdbrown

hughdbrown Feb 5, 2014

Why not:

new_plugins = [p(*args, **kwargs) for p in self._plugins]
return PluginManager(new_plugins)

def call(self, methodname, *args, **kwargs):
"""Call a common method on all the plugins, if it exists."""
Expand Down
5 changes: 2 additions & 3 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,10 @@ def test_plugin(self):
class PluginManagerTestCase(unittest.TestCase):

def setUp(self):
self.m = manager.PluginManager()
self.m._plugins = [
self.m = manager.PluginManager([
mock.Mock(),
mock.Mock(),
]
])

def test_first(self):
self.m._plugins[0].x.return_value = 1
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tox]
envlist = py26,py27,py32
[testenv]
deps = mock
commands=./tests.py

0 comments on commit b2550b1

Please sign in to comment.