How to use _setup_func method in autotest

Best Python code snippet using autotest_python

functools.py

Source:functools.py Github

copy

Full Screen

...25 self._prefix = f'{BERT_ETL_S3_PREFIX}/func-tools/{func_or_prefix}'26 elif isinstance(func_or_prefix, types.FunctionType):27 func_path = f'{func_or_prefix.__module__}.{func_or_prefix.__name__}'28 self._prefix = f'{BERT_ETL_S3_PREFIX}/func-tools/{func_path}'29 self._setup_func(func_or_prefix)30 # self._setup_cache(func_or_prefix)31 else:32 raise NotImplementedError33 def _hash_inputs(self: PWN, *args, **kwargs) -> str:34 properties = []35 for arg in args:36 if not isinstance(arg, str):37 properties.append(str(arg))38 else:39 properties.append(arg)40 def _setup_func(self: PWN, func: types.FunctionType) -> None:41 func_spec = inspect.getfullargspec(func)42 # Only supports data-types that can be converted into strs right now43 # func_args_spec = ''.join([str(value) for value in func_spec.args[:]])44 # func_annotation_spec = ''.join([':'.join([key, str(value)]) for key, value in func_spec.annotations.items()])45 # func_default_spec = ''.join([str(value) for value in func_spec.defaults[:]])46 # func_kword_spec = ''.join([str(value) for value in func_spec.kwonlyargs[:]])47 func_spec_key = ''.join([48 ''.join([str(value) for value in func_spec.args[:]]),49 ''.join([':'.join([key, str(value)]) for key, value in func_spec.annotations.items()]),50 ''.join([str(value) for value in func_spec.defaults[:]]),51 ''.join([str(value) for value in func_spec.kwonlyargs[:]]),52 ])53 etl_state_key = hashlib.sha256(func_spec_key.encode(ENCODING)).hexdigest()54 etl_state = ETLState(etl_state_key)55 # A question now rises in my mind. Do we want to pull down and maintain a global state from the __init__56 # method? Or is it better to run this logic in the function invocation?57 @python_functools.wraps(func)58 def _wrapper(*args, **kwargs) -> typing.Any:59 func_invocation_key = ''.join([60 ''.join([str(arg) for arg in args]),61 ''.join([':'.join([key, value]) for key, value in kwargs.items()]),62 ])63 s3_key = ''.join([self._prefix, func_spec_key, func_invocation_key])64 s3_key = hashlib.sha256(s3_key.encode(ENCODING)).hexdigest()65 s3_key = f'{self._prefix}/{s3_key}'66 etl_state.localize()67 if etl_state.contains(s3_key) is True:68 func_result = download_dataset(s3_key, os.environ['DATASET_BUCKET'], dict)69 return func_result70 else:71 func_result = func(*args, **kwargs)72 # We'll need to expand the followirg logic so that caching can cache more than simple python datatypes73 upload_dataset(func_result, s3_key, os.environ['DATASET_BUCKET'])74 # Add to etl_state after the upload, incase an error occurs during upload75 etl_state.contain(s3_key)76 etl_state.synchronize()77 return func_result78 self._wrapped_func = _wrapper79 return _wrapper80 def __call__(self: PWN, func: types.FunctionType, *rest, **kwargs) -> typing.Any:81 if isinstance(func, types.FunctionType):82 return self._setup_func(func)83 first_arg = func,84 func_args = first_arg + rest...

Full Screen

Full Screen

lazy_loader.py

Source:lazy_loader.py Github

copy

Full Screen

...32 self._setup()33 setattr(self._wrapped, name, value)34 def _setup(self):35 if self._wrapped is empty:36 self._wrapped = self._setup_func()37 # Return a meaningful representation of the lazy object for debugging38 # without evaluating the wrapped object.39 def __repr__(self):40 if self._wrapped is empty:41 repr_attr = self._setup_func42 else:43 repr_attr = self._wrapped44 return '<%s: %r>' % (type(self).__name__, repr_attr)45 def __copy__(self):46 if self._wrapped is empty:47 # If uninitialized, copy the wrapper. Use SimpleLazyObject, not48 # self.__class__, because the latter is proxied.49 return SimpleLazyObject(load_fn=self._setup_func, id=self.id, clz=self._clz, **self._eager_fields)50 else:...

Full Screen

Full Screen

_plugin_manager.py

Source:_plugin_manager.py Github

copy

Full Screen

1# © 2020 James R. Barlow: github.com/jbarlow832#3# This Source Code Form is subject to the terms of the Mozilla Public4# License, v. 2.0. If a copy of the MPL was not distributed with this5# file, You can obtain one at http://mozilla.org/MPL/2.0/.6import argparse7import importlib8import importlib.util9import sys10from functools import partial11from pathlib import Path12from typing import Callable, List, Tuple, Union13import pluggy14from ocrmypdf import pluginspec15from ocrmypdf.cli import get_parser, plugins_only_parser16class OcrmypdfPluginManager(pluggy.PluginManager):17 """pluggy.PluginManager that can fork.18 Capable of reconstructing itself in child workers.19 Arguments:20 setup_func: callback that initializes the plugin manager with all21 standard plugins22 """23 def __init__(24 self, *args, setup_func: Callable[[pluggy.PluginManager], None], **kwargs25 ):26 self._init_args = args27 self._setup_func = setup_func28 self._init_kwargs = kwargs29 super().__init__(*args, **kwargs)30 setup_func(self)31 def __getstate__(self):32 state = dict(33 _init_args=self._init_args,34 _setup_func=self._setup_func,35 _init_kwargs=self._init_kwargs,36 )37 return state38 def __setstate__(self, state):39 self.__init__(40 *state['_init_args'],41 setup_func=state['_setup_func'],42 **state['_init_kwargs'],43 )44def _setup_plugins(45 pm: pluggy.PluginManager, plugins: List[Union[str, Path]], builtins: bool = True46):47 pm.add_hookspecs(pluginspec)48 all_plugins: List[Union[str, Path]] = []49 if builtins:50 all_plugins.extend(51 [52 'ocrmypdf.builtin_plugins.ghostscript',53 'ocrmypdf.builtin_plugins.tesseract_ocr',54 ]55 )56 all_plugins.extend(plugins)57 for name in all_plugins:58 if isinstance(name, Path) or name.endswith('.py'):59 # Import by filename60 module_name = Path(name).stem61 spec = importlib.util.spec_from_file_location(module_name, name)62 module = importlib.util.module_from_spec(spec)63 sys.modules[module_name] = module64 spec.loader.exec_module(module)65 else:66 # Import by dotted module name67 module = importlib.import_module(name)68 pm.register(module)69def get_plugin_manager(plugins: List[str], builtins=True):70 pm = OcrmypdfPluginManager(71 project_name='ocrmypdf',72 setup_func=partial(_setup_plugins, plugins=plugins, builtins=builtins),73 )74 return pm75def get_parser_options_plugins(76 args,77) -> Tuple[argparse.ArgumentParser, argparse.Namespace, pluggy.PluginManager]:78 pre_options, _unused = plugins_only_parser.parse_known_args(args=args)79 plugin_manager = get_plugin_manager(pre_options.plugins)80 parser = get_parser()81 plugin_manager.hook.add_options(parser=parser) # pylint: disable=no-member82 options = parser.parse_args(args=args)...

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 autotest 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