Ejemplo n.º 1
0
    def test_pluginmeta(self):
        from pluggdapps.plugin import PluginMeta, Interface, PluginBase, \
                                      Singleton, plugin_init
        from pprint import pprint

        fn = lambda x: x.__name__
        refs = [
            'baseresource', 'commandcommands', 'commandconfig', 'commandls',
            'commandmounts', 'commandserve', 'commandunittest', 'httprequest',
            'httpresponse', 'plugin', 'rootapp', 'webapp'
        ]
        for r in refs:
            assert r in PluginMeta._pluginmap.keys()

        refs = [
            ICommand, IHTTPView, IHTTPRouter, IHTTPCookie, IHTTPRequest,
            IHTTPResource, IHTTPResponse, IHTTPOutBound, IHTTPServer
        ]
        refs = map(fn, refs)
        for r in refs:
            assert r in PluginMeta._interfmap.keys()

        m = {}
        for k in PluginMeta._implementers.keys():
            for x, y in PluginMeta._implementers[k].items():
                m.setdefault(y, []).append(k)
        for y in plugins():
            cls = PluginMeta._pluginmap[y]['cls']
            assert sorted(cls._interfs, key=fn) == sorted(m[cls], key=fn)

        assert not hasattr(Interface, '_interfs')
        assert not hasattr(PluginBase, '_interfs')

        # Test Plugin's __init__ chain and masterinit
        class A(Plugin):
            def __init__(self, a):
                self.varA = a * 2

        class B(A):
            def __init__(self, a):
                self.varB = a * 3
                self._super_init(__class__, a)

        class C(B):
            pass

        plugin_init()

        a = query_plugin(None, ISettings, 'a', 10)
        b = query_plugin(None, ISettings, 'b', 20)
        c = query_plugin(None, ISettings, 'c', 30)

        assert a.varA == 20
        assert b.varA == 40 and b.varB == 60
        assert c.varA == 60 and c.varB == 90
Ejemplo n.º 2
0
    def test_pluginmeta( self ):
        from pluggdapps.plugin import PluginMeta, Interface, PluginBase, \
                                      Singleton, plugin_init
        from pprint import pprint

        fn = lambda x : x.__name__
        refs = [
                'baseresource', 'commandcommands', 'commandconfig',
                'commandls', 'commandmounts', 'commandserve', 'commandunittest',
                'httprequest', 'httpresponse', 'plugin', 'rootapp', 'webapp' ]
        for r in refs : assert r in PluginMeta._pluginmap.keys()

        refs = [ ICommand, IHTTPView, IHTTPRouter, IHTTPCookie,
                 IHTTPRequest, IHTTPResource, IHTTPResponse, 
                 IHTTPOutBound, IHTTPServer ]
        refs = map( fn,  refs )
        for r in refs : assert r in PluginMeta._interfmap.keys()

        m = {}
        for k in PluginMeta._implementers.keys() :
            for x,y in PluginMeta._implementers[k].items() :
                m.setdefault( y, [] ).append( k )
        for y in plugins() :
            cls = PluginMeta._pluginmap[y]['cls']
            assert sorted(cls._interfs, key=fn) == sorted(m[cls], key=fn)

        assert not hasattr( Interface, '_interfs' )
        assert not hasattr( PluginBase, '_interfs' )

        # Test Plugin's __init__ chain and masterinit
        class A( Plugin ):
            def __init__( self, a ):
                self.varA = a * 2

        class B( A ):
            def __init__( self, a ):
                self.varB = a * 3
                self._super_init( __class__, a )

        class C( B ):
            pass

        plugin_init()

        a = query_plugin( None, ISettings, 'a', 10 )
        b = query_plugin( None, ISettings, 'b', 20 )
        c = query_plugin( None, ISettings, 'c', 30 )

        assert a.varA == 20
        assert b.varA == 40 and  b.varB == 60
        assert c.varA == 60 and  c.varB == 90
Ejemplo n.º 3
0
    def test_singleton( self ):
        class A( Plugin ):
            def __init__( self, a ):
                self.varA = a * 2

        class D( Singleton ):
            pass

        plugin_init()

        a = query_plugin( None, ISettings, 'a', 10 )
        b = query_plugin( None, ISettings, 'a', 20 )
        assert id(a) != id(b)
        a = query_plugin( None, ISettings, 'd' )
        b = query_plugin( None, ISettings, 'd' )
        assert id(a) == id(b)
Ejemplo n.º 4
0
    def test_singleton(self):
        class A(Plugin):
            def __init__(self, a):
                self.varA = a * 2

        class D(Singleton):
            pass

        plugin_init()

        a = query_plugin(None, ISettings, 'a', 10)
        b = query_plugin(None, ISettings, 'a', 20)
        assert id(a) != id(b)
        a = query_plugin(None, ISettings, 'd')
        b = query_plugin(None, ISettings, 'd')
        assert id(a) == id(b)