def test__register_all(self): """ registration.register_all: handles registration for all hook types defined for the provided plugin. """ # register all for plugin registration.register_all(MockPlugin) command = MockPlugin.command self.assertIn(command, [x[0] for x in registration._command_hooks]) self.assertIn('apps_sup', [x[0] for x in registration._option_hooks]) found_count = 0 for k, v in registration._event_hooks.iteritems(): if k in ('task_start', 'task_run', 'task_end'): name, get_plugin = v[0] plugin_obj = get_plugin() self.assertEqual(name, MockPlugin.name) self.assertIsInstance(plugin_obj, MockPlugin) found_count += 1 self.assertEqual(found_count, 3)
def __init__(cls, name, bases, attrs): """ Class definition is initialized: checks for required attributes and registers the plugin class if it passes all checks. """ super(_PluginMeta, cls).__init__(name, bases, attrs) # check if class is instance of meta base if any([b for b in bases if isinstance(b, _PluginMeta)]): # parents # Doesn't have all the required attributes, bail. for attr in _REQUIRED_ATTRIBS: if not attrs.get(attr): return # must define at least one command = attrs.get('command') if not attrs.get('events') and not command: return if command: # must be a string if not isinstance(command, basestring): return # and not empty. strip spaces from class's command name cls.command = cls.command.strip() if not cls.command: return # check plugin target version against program version if not focus.version.compare_version(attrs['target_version']): return # if we made it this far, then it's a valid plugin: # let's add it to the registries registration.register_all(cls)