How to use _dot_lookup method in autotest

Best Python code snippet using autotest_python Github


Full Screen

1# Python Libraries / Librerías Python2from importlib import import_module3from pkgutil import iter_modules4# Application Libraries / Librerías de la Aplicación5# Preconditions / Precondiciones6class Importer () :7 #adopted from mock.mock._dot_lookup8 @staticmethod9 def _dot_lookup ( obj : object, attribute : str, importModule : str ) :10 '''11 Recursively import packages (if needed) by dotes.12 '''13 try :14 return getattr ( obj, attribute )15 except AttributeError :16 import_module ( importModule )17 Importer._walk_modules ( importModule )18 return getattr ( obj, attribute )19 #adopted from scrapy20 @staticmethod21 def _walk_modules ( importModule ) :22 """23 Loads a module and all its submodules from the given module path and24 returns them. If *any* module throws an exception while importing, that25 exception is thrown back.26 """27 # Support for namespace packages is added. See PEP 420.28 # Namespace packages are a mechanism for splitting a single Python package across multiple directories on disk.29 # When interpreted encounter with non-empty __path__ attribute it adds modules found in those locations30 # to the current package.31 mods = []32 mod = import_module ( importModule )33 mods.append ( mod )34 if hasattr ( mod, '__path__' ) :35 for _, subpath, ispkg in iter_modules ( mod.__path__ ) :36 fullpath = importModule + '.' + subpath37 if ispkg :38 mods += Importer._walk_modules ( fullpath )39 else:40 submod = import_module ( fullpath )41 mods.append ( submod )42 return mods43 #adopted from mock.mock._importer44 @staticmethod45 def importer ( target ) :46 '''47 Convert str to Python construct that target is represented.48 This method will recursively import packages (if needed)49 Following dot notation from left to right. If the component50 exists in packagage (is defined and imported) it will be used,51 otherwrise, it will be imported.52 This method supports PEP 420 (implicit Namespace Packages).53 Note: only compile-time construct is supported.54 Note: no instances will be returned from here, only classes.55 :param target: str to lookup56 :return: function/module/class, etc57 '''58 components = target.split ( '.' )59 importModule = components.pop ( 0 )60 obj = import_module ( importModule )61 Importer._walk_modules ( importModule )62 for attribute in components :63 importModule += f".{ attribute }"64 obj = Importer._dot_lookup ( obj, attribute, importModule )...

Full Screen

Full Screen Github


Full Screen

...5:license: Apache License 2.0, see LICENSE for more details.6"""7from __future__ import absolute_import8from functools import wraps9def _dot_lookup(thing, comp, import_path):10 try:11 return getattr(thing, comp)12 except AttributeError:13 __import__(import_path)14 return getattr(thing, comp)15def import_string(target):16 components = target.split('.')17 import_path = components.pop(0)18 thing = __import__(import_path)19 for comp in components:20 import_path += ".%s" % comp21 thing = _dot_lookup(thing, comp, import_path)22 return thing23class PatchContext(object):24 def __init__(self, target, callback):25 target, attr = target.rsplit('.', 1)26 target = import_string(target)27 self.func = getattr(target, attr)28 = target29 self.attr = attr30 self.callback = callback31 def __enter__(self):32 @wraps(getattr(, self.attr))33 def wrapped(*args, **kwargs):34 __traceback_hide__ = True # NOQA35 return self.callback(self.func, *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:


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?