Best Python code snippet using slash
manager.py
Source:manager.py
1#coding:utf-82import functools3from cactus.utils.internal import getargspec4from cactus.plugin import defaults5class PluginManager(object):6 def __init__(self, site, loaders):7 self.site = site8 self.loaders = loaders9 self.reload()10 for plugin_method in defaults.DEFAULTS:11 if not hasattr(self, plugin_method):12 setattr(self, plugin_method, functools.partial(self.call, plugin_method))13 def reload(self):14 plugins = []15 for loader in self.loaders:16 plugins.extend(loader.load())17 self.plugins = sorted(plugins, key=lambda plugin: plugin.ORDER)18 def call(self, method, *args, **kwargs):19 """20 Call each plugin21 """22 for plugin in self.plugins:23 _meth = getattr(plugin, method)24 _meth(*args, **kwargs)25 def preBuildPage(self, site, page, context, data):26 """27 Special call as we have changed the API for this.28 We have two calling conventions:29 - The new one, which passes page, context, data30 - The deprecated one, which also passes the site (Now accessible via the page)31 """32 for plugin in self.plugins:33 # Find the correct calling convention34 new = [page, context, data]35 deprecated = [site, page, context, data]36 arg_lists = dict((len(l), l) for l in [deprecated, new])37 try:38 # Try to find the best calling convention39 n_args = len(getargspec(plugin.preBuildPage).args)40 # Just use the new calling convention if there's fancy usage of41 # *args, **kwargs that we can't control.42 arg_list = arg_lists.get(n_args, new)43 except NotImplementedError:44 # If we can't get the number of args, use the new one.45 arg_list = new46 # Call with the best calling convention we have.47 # If that doesn't work, then we'll let the error escalate.48 context, data = plugin.preBuildPage(*arg_list)...
__init__.py
Source:__init__.py
1import sys2def delayed_plugin(module, fname, package='divisi2.algorithms'):3 modname = package+'.'+module4 def plugin_method(*args, **kw):5 """6 Sorry, this meta-code won't be too informative. If you're seeing this in7 IPython's ?? mode, try a single question mark instead.8 """9 __import__(modname)10 mod = sys.modules[modname]11 func = getattr(mod, fname)12 return func(*args, **kw)13 plugin_method.__name__ = fname14 plugin_method.__doc__ = """15 Import the %(fname)s algorithm and perform it on this matrix.16 More information is available in the documentation for17 :func:`%(modname)s.%(fname)s`.18 """ % locals()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!