Best Python code snippet using autotest_python
Importer.py
Source: Importer.py
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 )...
util.py
Source: util.py
...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 self.target = target29 self.attr = attr30 self.callback = callback31 def __enter__(self):32 @wraps(getattr(self.target, self.attr))33 def wrapped(*args, **kwargs):34 __traceback_hide__ = True # NOQA35 return self.callback(self.func, *args, **kwargs)...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!