How to use should_load method in localstack

Best Python code snippet using localstack_python

core.py

Source:core.py Github

copy

Full Screen

...23 name: str24 requirements: List[str]25 def is_active(self) -> bool:26 # FIXME: remove after release (would currently break localstack-ext)27 return self.should_load()28 def should_load(self) -> bool:29 return True30 def load(self, *args, **kwargs):31 """32 Called by a PluginLoader when it loads the Plugin.33 """34 return None35PluginType = Type[Plugin]36PluginFactory = Callable[[], Plugin]37class PluginSpec:38 """39 A PluginSpec describes a plugin through a namespace and its unique name within in that namespace, and holds the40 imported code that can instantiate the plugin (a PluginFactory). In the simplest case, the PluginFactory that can41 just be the Plugin's class.42 Internally a PluginSpec is essentially a wrapper around an importlib EntryPoint. An entrypoint is a tuple: (43 "name", "module:object") inside a namespace that can be loaded. The entrypoint object of a LocalStack Plugin can44 point to to a PluginSpec, or a Plugin that defines it's own namespace and name, in which case the PluginSpec will45 be instantiated dynamically by, e.g., a PluginSpecResolver.46 """47 namespace: str48 name: str49 factory: PluginFactory50 def __init__(51 self,52 namespace: str,53 name: str,54 factory: PluginFactory,55 ) -> None:56 super().__init__()57 self.namespace = namespace58 self.name = name59 self.factory = factory60 def __str__(self):61 return "PluginSpec(%s.%s = %s)" % (self.namespace, self.name, self.factory)62 def __repr__(self):63 return self.__str__()64 def __eq__(self, other):65 return (66 self.namespace == other.namespace67 and self.name == other.name68 and self.factory == other.factory69 )70class PluginFinder(abc.ABC):71 """72 Basic abstractions to find plugins, either at build time (e.g., using the PackagePathPluginFinder) or at run time73 (e.g., using StevedorePluginFinder that finds plugins from entrypoints)74 """75 def find_plugins(self) -> List[PluginSpec]:76 raise NotImplementedError # pragma: no cover77class PluginSpecResolver:78 """79 A PluginSpecResolver finds or creates PluginSpec instances from sources, e.g., from analyzing a Plugin class.80 """81 def resolve(self, source: Any) -> PluginSpec:82 """83 Tries to create a PluginSpec from the given source.84 :param source: anything that can produce a PluginSpec (Plugin class, ...)85 :return: a PluginSpec instance86 """87 if isinstance(source, PluginSpec):88 return source89 if inspect.isclass(source):90 if issubclass(source, Plugin):91 return PluginSpec(source.namespace, source.name, source)92 if inspect.isfunction(source):93 spec = getattr(source, "__pluginspec__", None)94 if spec and isinstance(spec, PluginSpec):95 return spec96 # TODO: add more options to specify plugin specs97 raise ValueError("cannot resolve plugin specification from %s" % source)98class PluginLifecycleListener: # pragma: no cover99 """100 Listener that can be attached to a PluginManager to react to plugin lifecycle events.101 """102 def on_resolve_exception(self, namespace: str, entrypoint, exception: Exception):103 pass104 def on_resolve_after(self, plugin_spec: PluginSpec):105 pass106 def on_init_exception(self, plugin_spec: PluginSpec, exception: Exception):107 pass108 def on_init_after(self, plugin_spec: PluginSpec, plugin: Plugin):109 pass110 def on_load_before(111 self,112 plugin_spec: PluginSpec,113 plugin: Plugin,114 load_args: Union[List, Tuple],115 load_kwargs: Dict,116 ):117 pass118 def on_load_after(self, plugin_spec: PluginSpec, plugin: Plugin, load_result: Any = None):119 pass120 def on_load_exception(self, plugin_spec: PluginSpec, plugin: Plugin, exception: Exception):121 pass122class FunctionPlugin(Plugin):123 """124 Exposes a function as a Plugin.125 """126 fn: Callable127 def __init__(128 self,129 fn: Callable,130 should_load: Union[bool, Callable[[], bool]] = None,131 load: Callable = None,132 ) -> None:133 super().__init__()134 self.fn = fn135 self._should_load = should_load136 self._load = load137 def __call__(self, *args, **kwargs):138 return self.fn(*args, **kwargs)139 def load(self, *args, **kwargs):140 if self._load:141 return self._load(*args, **kwargs)142 def should_load(self) -> bool:143 if self._should_load is not None:144 if type(self._should_load) == bool:145 return self._should_load146 else:147 return self._should_load()148 return True149def plugin(150 namespace, name=None, should_load: Union[bool, Callable[[], bool]] = None, load: Callable = None151):152 """153 Expose a function as discoverable and loadable FunctionPlugin.154 :param namespace: the plugin namespace155 :param name: the name of the plugin (by default the function name will be used)156 :param should_load: optional either a boolean value or a callable returning a boolean157 :param load: optional load function158 :return: plugin decorator159 """160 def wrapper(fn):161 plugin_name = name or fn.__name__...

Full Screen

Full Screen

situation_time_jump.py

Source:situation_time_jump.py Github

copy

Full Screen

1from sims4.tuning.tunable import HasTunableSingletonFactory, TunableVariant2import services3class _SituationTimeJump:4 def should_load(self, seed):5 raise NotImplementedError6 def require_guest_list_regeneration(self, situation):7 raise NotImplementedError8class SituationTimeJumpDisallow(HasTunableSingletonFactory):9 def should_load(self, seed):10 if services.current_zone().time_has_passed_in_world_since_zone_save():11 return False12 return True13 def require_guest_list_regeneration(self, situation):14 return False15class SituationTimeJumpAllow(HasTunableSingletonFactory):16 def should_load(self, seed):17 return True18 def require_guest_list_regeneration(self, situation):19 if services.current_zone().time_has_passed_in_world_since_zone_save():20 return True21 return False22class SituationTimeJumpSimulate(SituationTimeJumpAllow):23 def should_load(self, seed):24 if not services.current_zone().time_has_passed_in_world_since_zone_save():25 return True26 else:27 situation_type = seed.situation_type28 if situation_type is not None and situation_type.should_load_after_time_jump(seed):29 seed.allow_time_jump = True30 return True31 return False32SITUATION_TIME_JUMP_DISALLOW = SituationTimeJumpDisallow()33class TunableSituationTimeJumpVariant(TunableVariant):34 def __init__(self, *args, **kwargs):...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful