Esempio n. 1
0
    def test_activatePlugin( self ):

        parent = DummyFolder()
        foo_plugin = DummyPlugin()
        directlyProvides( foo_plugin,  ( IFoo, ) )
        parent._setObject( 'foo_plugin', foo_plugin )

        preg = self._makeOne().__of__(parent)

        preg.activatePlugin( IFoo, 'foo_plugin')

        idlist = preg.listPluginIds( IFoo )
        self.assertEqual( len( idlist ), 1 )
        self.assertEqual( idlist[0], 'foo_plugin' )
Esempio n. 2
0
    def test_activatePlugin_then_remove_interface(self):

        parent = DummyFolder()
        foo_plugin = DummyPlugin()
        directlyProvides(foo_plugin, (IFoo, ))
        parent._setObject('foo_plugin', foo_plugin)

        preg = self._makeOne().__of__(parent)

        preg.activatePlugin(IFoo, 'foo_plugin')

        replacement = DummyPlugin()
        parent._delObject('foo_plugin')
        parent._setObject('foo_plugin', replacement)

        idlist = preg.listPluginIds(IFoo)
        self.assertEqual(len(idlist), 1)  # note discrepancy

        plugins = preg.listPlugins(IFoo)
        self.assertEqual(len(plugins), 0)
Esempio n. 3
0
    def test_activatePlugin_then_remove_interface( self ):

        parent = DummyFolder()
        foo_plugin = DummyPlugin()
        directlyProvides( foo_plugin,  ( IFoo, ) )
        parent._setObject( 'foo_plugin', foo_plugin )

        preg = self._makeOne().__of__(parent)

        preg.activatePlugin( IFoo, 'foo_plugin')

        replacement = DummyPlugin()
        parent._delObject( 'foo_plugin' )
        parent._setObject( 'foo_plugin', replacement )

        idlist = preg.listPluginIds( IFoo )
        self.assertEqual( len( idlist ), 1 )  # note discrepancy

        plugins = preg.listPlugins( IFoo )
        self.assertEqual( len( plugins ), 0 )
Esempio n. 4
0
    def test_movePluginsDown( self ):

        parent = DummyFolder()
        foo_plugin = DummyPlugin()
        directlyProvides( foo_plugin, ( IFoo, ) )
        parent._setObject( 'foo_plugin', foo_plugin )

        bar_plugin = DummyPlugin()
        directlyProvides( bar_plugin, ( IFoo, ) )
        parent._setObject( 'bar_plugin', bar_plugin )

        baz_plugin = DummyPlugin()
        directlyProvides( baz_plugin, ( IFoo, ) )
        parent._setObject( 'baz_plugin', baz_plugin )

        preg = self._makeOne().__of__(parent)

        preg.activatePlugin( IFoo, 'foo_plugin' )
        preg.activatePlugin( IFoo, 'bar_plugin' )
        preg.activatePlugin( IFoo, 'baz_plugin' )

        self.assertRaises( ValueError, preg.movePluginsDown
                         , IFoo, ( 'quux_plugin', ) )

        preg.movePluginsDown( IFoo, ( 'foo_plugin', 'bar_plugin' ) )

        idlist = preg.listPluginIds( IFoo )
        self.assertEqual( len( idlist ), 3 )

        self.assertEqual( idlist[0], 'baz_plugin' )
        self.assertEqual( idlist[1], 'foo_plugin' )
        self.assertEqual( idlist[2], 'bar_plugin' )
Esempio n. 5
0
    def test_getAllPlugins(self):

        parent = DummyFolder()
        foo_plugin = DummyPlugin()
        directlyProvides(foo_plugin, (IFoo, ))
        parent._setObject('foo_plugin', foo_plugin)

        bar_plugin = DummyPlugin()
        directlyProvides(bar_plugin, (IFoo, ))
        parent._setObject('bar_plugin', bar_plugin)

        baz_plugin = DummyPlugin()
        directlyProvides(baz_plugin, (IFoo, ))
        parent._setObject('baz_plugin', baz_plugin)

        preg = self._makeOne().__of__(parent)

        first = preg.getAllPlugins('IFoo')

        self.assertEqual(len(first['active']), 0)

        self.assertEqual(len(first['available']), 3)
        self.failUnless('foo_plugin' in first['available'])
        self.failUnless('bar_plugin' in first['available'])
        self.failUnless('baz_plugin' in first['available'])

        preg.activatePlugin(IFoo, 'foo_plugin')

        second = preg.getAllPlugins('IFoo')

        self.assertEqual(len(second['active']), 1)
        self.failUnless('foo_plugin' in second['active'])

        self.assertEqual(len(second['available']), 2)
        self.failIf('foo_plugin' in second['available'])
        self.failUnless('bar_plugin' in second['available'])
        self.failUnless('baz_plugin' in second['available'])

        preg.activatePlugin(IFoo, 'bar_plugin')
        preg.activatePlugin(IFoo, 'baz_plugin')

        third = preg.getAllPlugins('IFoo')

        self.assertEqual(len(third['active']), 3)
        self.failUnless('foo_plugin' in third['active'])
        self.failUnless('bar_plugin' in third['active'])
        self.failUnless('baz_plugin' in third['active'])

        self.assertEqual(len(third['available']), 0)
Esempio n. 6
0
    def test_getAllPlugins( self ):

        parent = DummyFolder()
        foo_plugin = DummyPlugin()
        directlyProvides( foo_plugin, ( IFoo, ) )
        parent._setObject( 'foo_plugin', foo_plugin )

        bar_plugin = DummyPlugin()
        directlyProvides( bar_plugin, ( IFoo, ) )
        parent._setObject( 'bar_plugin', bar_plugin )

        baz_plugin = DummyPlugin()
        directlyProvides( baz_plugin, ( IFoo, ) )
        parent._setObject( 'baz_plugin', baz_plugin )

        preg = self._makeOne().__of__( parent )

        first = preg.getAllPlugins( 'IFoo' )

        self.assertEqual( len( first[ 'active' ] ), 0 )

        self.assertEqual( len( first[ 'available' ] ), 3 )
        self.failUnless( 'foo_plugin' in first[ 'available' ] )
        self.failUnless( 'bar_plugin' in first[ 'available' ] )
        self.failUnless( 'baz_plugin' in first[ 'available' ] )

        preg.activatePlugin( IFoo, 'foo_plugin' )

        second = preg.getAllPlugins( 'IFoo' )

        self.assertEqual( len( second[ 'active' ] ), 1 )
        self.failUnless( 'foo_plugin' in second[ 'active' ] )

        self.assertEqual( len( second[ 'available' ] ), 2 )
        self.failIf( 'foo_plugin' in second[ 'available' ] )
        self.failUnless( 'bar_plugin' in second[ 'available' ] )
        self.failUnless( 'baz_plugin' in second[ 'available' ] )

        preg.activatePlugin( IFoo, 'bar_plugin' )
        preg.activatePlugin( IFoo, 'baz_plugin' )

        third = preg.getAllPlugins( 'IFoo' )

        self.assertEqual( len( third[ 'active' ] ), 3 )
        self.failUnless( 'foo_plugin' in third[ 'active' ] )
        self.failUnless( 'bar_plugin' in third[ 'active' ] )
        self.failUnless( 'baz_plugin' in third[ 'active' ] )

        self.assertEqual( len( third[ 'available' ] ), 0 )
Esempio n. 7
0
    def test_movePluginsDown( self ):

        parent = DummyFolder()
        foo_plugin = DummyPlugin()
        directlyProvides( foo_plugin, ( IFoo, ) )
        parent._setObject( 'foo_plugin', foo_plugin )

        bar_plugin = DummyPlugin()
        directlyProvides( bar_plugin, ( IFoo, ) )
        parent._setObject( 'bar_plugin', bar_plugin )

        baz_plugin = DummyPlugin()
        directlyProvides( baz_plugin, ( IFoo, ) )
        parent._setObject( 'baz_plugin', baz_plugin )

        preg = self._makeOne().__of__(parent)

        preg.activatePlugin( IFoo, 'foo_plugin' )
        preg.activatePlugin( IFoo, 'bar_plugin' )
        preg.activatePlugin( IFoo, 'baz_plugin' )

        self.assertRaises( ValueError, preg.movePluginsDown
                         , IFoo, ( 'quux_plugin', ) )

        preg.movePluginsDown( IFoo, ( 'foo_plugin', 'bar_plugin' ) )

        idlist = preg.listPluginIds( IFoo )
        self.assertEqual( len( idlist ), 3 )

        self.assertEqual( idlist[0], 'baz_plugin' )
        self.assertEqual( idlist[1], 'foo_plugin' )
        self.assertEqual( idlist[2], 'bar_plugin' )

        # Moving the lowest plugin down should not change anything.
        preg.movePluginsDown( IFoo, ( 'bar_plugin', ) )
        idlist = preg.listPluginIds( IFoo )
        self.assertEqual(idlist, 
                         ('baz_plugin', 'foo_plugin', 'bar_plugin'))

        # Moving the lowest plugin and another one could change something.
        preg.movePluginsDown( IFoo, ( 'bar_plugin', 'baz_plugin' ) )
        idlist = preg.listPluginIds( IFoo )
        self.assertEqual(idlist, 
                         ('foo_plugin', 'baz_plugin', 'bar_plugin'))