How to use fully_qualified_class_name method in localstack

Best Python code snippet using localstack_python

util.py

Source:util.py Github

copy

Full Screen

1import cPickle2import random3import string4# TODO: This needs to be enhanced into a name service that guarantees a5# TODO: unique name across multiple processes.6def generate_random_name(prefix, length):7 nonce_len = length - len(prefix)8 if nonce_len <= 0:9 raise Exception("Invalid name length ({})".format(length))10 return prefix + "".join([random.choice(string.hexdigits) for i in xrange(nonce_len)])11def create_class_instance(fully_qualified_class_name, *args, **kwargs):12 """13 Instantiates an object of type given by fully_qualified_class_name, and14 passes the supplied args and kwargs to the class's init method.15 :param fully_qualified_class_name: the fully qualified name of the class to instantiate16 :param args: positional arguments to pass to the class's init method17 :param kwargs: keyword arguments to pass to the class's init method18 :return:19 """20 try:21 tokens = fully_qualified_class_name.split('.')22 module_name = '.'.join(tokens[:-1])23 class_name = tokens[-1]24 module = __import__(module_name)25 for token in module_name.split('.')[1:]:26 module = getattr(module, token)27 callable = getattr(module, class_name)28 instance = callable(*args, **kwargs)29 except Exception as e:30 raise Exception("Failed to construct instance of class {}".format(fully_qualified_class_name))31 return instance32class Singleton(type):33 # A dictionary that serves as a registry of singletons34 _registry = {}35 def __call__(cls, *args, **kwargs):36 # If class previously instantiated and added to the registry then37 # return that same object; otherwise, create a new instance and38 # add it to the registry39 if cls not in cls._registry:40 cls._registry[cls] = super(Singleton, cls).__call__(*args, **kwargs)41 return cls._registry[cls]42 @classmethod43 def _remove(cls, target_cls):44 if cls._registry.has_key(target_cls):45 cls._registry.pop(target_cls)46 @classmethod47 def _clear(cls):48 cls._registry.clear()49class MsgUtils(object):50 @staticmethod51 def serialize(obj):52 return cPickle.dumps(obj)53 @staticmethod54 def deserialize(serialized_obj):55 return cPickle.loads(serialized_obj) if serialized_obj else None56class RosMsgUtils(object):57 @staticmethod58 def wrap(obj, cls, prop):59 wrapper_cls = cls()60 setattr(wrapper_cls, prop, obj)61 return wrapper_cls62 @staticmethod63 def unwrap(obj, prop):64 if obj is not None and hasattr(obj, prop):65 return getattr(obj, prop)66 else:...

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