Пример #1
0
class PyPluginManagerTestCase(unittest.TestCase):
    def setUp(self):
	self.plugin_dirs = (os.path.abspath("pyPlugin_plugins"), )	
	self.services = ServiceCollection()
	self.services.add("connect", dummy_function)
	one_service = ServiceTest()
	self.services.add("service", one_service)

    def test_discover(self):
        pm = PyPluginManager(self.plugin_dirs, services=self.services)
	self.assertEqual(len(pm), 0)
	pm.discover()
	self.assertEqual(len(pm), 1)

    def test_autodiscover(self):
        pm = PyPluginManager(self.plugin_dirs, services=self.services, auto_init=True)
        self.assertEqual(len(pm), 1)

    def test_magic_methods(self):
        pm = PyPluginManager(self.plugin_dirs, services=self.services)
	#check the python __*method*__ ;)
	self.assertEqual('plugin_test' in pm, False)
	self.assertEqual(pm['plugin_test'], None)
        pm.discover()
	self.assertEqual('plugin_test' in pm, True)
	for p in pm:
		self.assertTrue(pm[p])

    def test_call_from_plugin(self):
        pm = PyPluginManager(self.plugin_dirs, services=self.services, auto_init=True)
        p = pm['plugin_test']
	#call a plugin method
        self.assertTrue(p.work())

    def test_load_one(self):
        pm = PyPluginManager(self.plugin_dirs, services=self.services, auto_init=True)
	#check load
	pm.load('plugin_test')
	self.assertEqual(len(pm), 1)
	
    def test_proxy_service(self): 
        pm = PyPluginManager(self.plugin_dirs, services=self.services, auto_init=True)
	p = pm['plugin_test']
	#emnulate a signal from the app
	p.say_hi("martin", "alderete", edad=25)
	#test if the *service* is proxy
	self.assertEqual('Proxy@' in repr(p.service), True)

    def test_function_service(self):
        pm = PyPluginManager(self.plugin_dirs, services=self.services, auto_init=True)
	p = pm['plugin_test']
	#check if the *service function* is proxy
        self.assertEqual('ProxyToFunction@' in repr(p.connect), True)     
        signals[signal_name].append({'method': func_to_call})
    

def emit(signal_name, *args, **kwds):
    global signals
    if signal_name in signals:
        for data in signals[signal_name]:
            method = data['method']
            #Call the method
            print method(*args, **kwds)



if __name__ == '__main__':
    plugin_dirs = (os.path.abspath("pyPlugin_plugins"), )  
    services_to_plugins = ServiceCollection()
    #provide a SERVICE to the plugins
    services_to_plugins.add("connect", connect)
    mb = MessageBox('pyplugin_message_box')
    pm = PyPluginManager(plugin_dirs, services_to_plugins, message_box=mb)
    pm.discover()
    pm.load_all()
    if len(pm):
        print "Listing all the plugins:"
	print "========================"
	for p in pm:
            print "    %s - %s" % (p, pm[p].get_info())
        print "\n"
    answer = True
    print 'Valid usernames to emit signals are: (admin, pyplugin)'
    while answer:
Пример #3
0
    def setUp(self):
	self.plugin_dirs = (os.path.abspath("pyPlugin_plugins"), )	
	self.services = ServiceCollection()
	self.services.add("connect", dummy_function)
	one_service = ServiceTest()
	self.services.add("service", one_service)