Пример #1
0
 def test_find(self):
     plugin = Mock()
     cnt = Container()
     cnt.add(plugin)
     p = cnt.find(plugin.name)
     self.assertEqual(p, plugin)
     p = cnt.find('joe')
     self.assertEqual(p, None)
Пример #2
0
 def test_add(self):
     plugin = Mock()
     cnt = Container()
     cnt.add(plugin)
     self.assertEqual(cnt.plugins, {
         plugin.name: plugin,
         plugin.path: plugin
     })
Пример #3
0
 def test_add_with_names(self):
     plugin = Mock()
     names = ['A', 'B']
     cnt = Container()
     cnt.add(plugin, *names)
     self.assertEqual(cnt.plugins, {
         plugin.path: plugin,
         names[0]: plugin,
         names[1]: plugin
     })
Пример #4
0
 def test_delete(self):
     plugin = Mock()
     plugin2 = Mock()
     names = ['A', 'B']
     cnt = Container()
     cnt.add(plugin, *names)
     cnt.add(plugin2)
     cnt.delete(plugin)
     self.assertEqual(cnt.plugins, {
         plugin2.name: plugin2,
         plugin2.path: plugin2
     })
Пример #5
0
 def help(self):
     """
     Show information about loaded plugins.
     :return: Information
     :rtype: str
     """
     s = list()
     s.append('Plugins:')
     container = Container()
     for p in container.all():
         if not p.enabled:
             continue
         # plugin
         s.append('')
         s.append(indent('<plugin> %s', 2, p.name))
         # classes
         s.append(indent('Classes:', 4))
         for n, v in p.dispatcher.catalog.items():
             if inspect.ismodule(v):
                 continue
             s.append(indent('<class> %s', 6, n))
             s.append(indent('methods:', 8))
             for n, v in inspect.getmembers(v, inspect.ismethod):
                 fn = v.im_func
                 if not hasattr(fn, 'gofer'):
                     continue
                 s.append(indent(signature(n, fn), 10))
         # functions
         s.append(indent('Functions:', 4))
         for n, v in p.dispatcher.catalog.items():
             if not inspect.ismodule(v):
                 continue
             for n, v in inspect.getmembers(v, inspect.isfunction):
                 fn = v
                 if not hasattr(fn, 'gofer'):
                     continue
                 s.append(indent(signature(n, fn), 6))
     s.append('')
     s.append('Actions:')
     for a in [(a.name(), a.interval) for a in Actions().collated()]:
         s.append('  %s %s' % a)
     return '\n'.join(s)
Пример #6
0
 def unload(self, path):
     container = Container()
     return container.unload(path)
Пример #7
0
 def reload(self, path):
     container = Container()
     return container.reload(path)
Пример #8
0
 def cancel(self, sn=None, criteria=None):
     container = Container()
     admin = Admin(container)
     return admin.cancel(sn=sn, criteria=criteria)
Пример #9
0
 def show(self):
     container = Container()
     admin = Admin(container)
     return admin.help()
Пример #10
0
 def test_call(self):
     cnt = Container()
     cnt.plugins = {'A': 1, 'B': 2, 'C': 2}
     plugins = cnt.all()
     self.assertEqual(plugins, [1, 2])
Пример #11
0
 def test_init(self):
     cnt = Container()
     self.assertEqual(cnt.plugins, {})