movePluginsUp when called on the top plugin moves it down
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope PAS |
Fix Released
|
Low
|
Wichert Akkerman |
Bug Description
This is for the PluginRegistry product.
When you call movePluginsUp on the plugin that is already the top one, it is actually moved to the bottom. And the bottom plugin is moved to the top instead.
Most interesting is the simple case where you have two plugins registered for an interface.
- All four combinations of calling movePluginsUp or Down on the top or the bottom one have the same result: the positions are switched.
- Calling two of those random actions after one another has zero end effect.
This can be fixed with the below patch, with tests.
Index: tests/test_
=======
--- tests/test_
+++ tests/test_
@@ -208,6 +208,19 @@
+ # Moving the top plugin up should not change anything.
+ preg.movePluginsUp( IFoo, ( 'bar_plugin', ) )
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqua
+ ('bar_plugin', 'baz_plugin', 'foo_plugin'))
+
+ # Moving the top plugin and another one could change something.
+ preg.movePluginsUp( IFoo, ( 'bar_plugin', 'foo_plugin' ) )
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqua
+ ('bar_plugin', 'foo_plugin', 'baz_plugin'))
+
+
def test_movePlugin
parent = DummyFolder()
@@ -241,6 +254,18 @@
+ # Moving the lowest plugin down should not change anything.
+ preg.movePlugin
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqua
+ ('baz_plugin', 'foo_plugin', 'bar_plugin'))
+
+ # Moving the lowest plugin and another one could change something.
+ preg.movePlugin
+ idlist = preg.listPluginIds( IFoo )
+ self.assertEqua
+ ('foo_plugin', 'baz_plugin', 'bar_plugin'))
+
def test_getAllPlugins( self ):
parent = DummyFolder()
Index: PluginRegistry.py
=======
--- PluginRegistry.py (revision 81966)
+++ PluginRegistry.py (working copy)
@@ -202,8 +202,9 @@
i2 = i1 - 1
- if i2 < 0: # wrap to bottom
- i2 = len( ids ) - 1
+ if i2 < 0:
+ # i1 is already on top
+ continue
ids[ i2 ], ids[ i1 ] = ids[ i1 ], ids[ i2 ]
@@ -227,8 +228,9 @@
i2 = i1 + 1
- if i2 == len( ids ): # wrap to top
- i2 = 0
+ if i2 == len( ids ):
+ # i1 is already on the bottom
+ continue
ids[ i2 ], ids[ i1 ] = ids[ i1 ], ids[ i2 ]
Changed in zope-pas: | |
assignee: | nobody → wichert |
importance: | Undecided → Low |
status: | New → In Progress |
Changed in zope-pas: | |
status: | In Progress → Fix Committed |
I will add the patch as an attachment, which can be applied like this: ns.txt
patch -p0 < patch-moveplugi