Best Python code snippet using autotest_python
All_in_all_OOP.py
Source:All_in_all_OOP.py
...7 __slots__ = ("_name", "_surname", "_age", "_someth_else")89 def __init__(self, name=None, surname=None, age=None, someth=None):1011 if Person.__isstr(name, surname) and Person.__isint(age):12 self._name = name13 self._surname = surname14 self._age = age15 self._someth_else = someth1617 @staticmethod18 def __isint(var):19 return isinstance(var, int)2021 @staticmethod22 def __isstr(var, num="sss"):23 return isinstance(var, str) and isinstance(num, str)2425 @property26 def pers(self):2728 return f"Person( {self._name} {self._surname} {self._age} {self._someth_else} )"2930 @pers.setter31 def pers(self, *args):3233 assert len(args) != 034 for elem in args:35 for g in elem:36
...
kernel.py
Source:kernel.py
...31 self.__kernel = None32 if kernel:33 # instance, developped by a user or subclasses of Kernel34 self.__kernel = kernel()35 elif self.__isstr(kernel):36 # is string37 self.__kernel = self.__create(kernel, *args, **kwargs)38 def __create(self, clsname, *args, **kwargs):39 """ Create an instance for a given class in str or name40 """41 obj = None42 for cls in self.registry:43 if clsname == cls.__name__:44 obj = cls(args)45 elif clsname == cls:46 obj = cls(args)47 if obj:48 # Initialize object49 obj.__init__(*args, **kwargs)50 else:51 print("Unknown class {}".format())52 return obj53 def __str__(self):54 #OK: return self.__kernel.__str__()55 #Failed return self.__getattr__(self.__kernel, '__str__')56 kernel_func_str_ = self.__getattr__(self.__kernel, '__str__')57 return kernel_func_str_()58 def __repr__(self):59 #return self.__kernel.__repr__()60 kernel_func_str_ = self.__getattr__(self.__kernel, '__repr__')61 return kernel_func_str_()62 def __call__(self, *args, **kwargs):63 return self.__kernel(*args, **kwargs)64 def __getattr__(self, obj, attr):65 """ get delegation to the object """66 #return getattr(obj, attr)67 try:68 return self.__kernel.__getattribute__(attr)69 except AttributeError:70 raise AttributeError('{0} object has no attribute `{1}`'71 .format(self.__class__.__name__, attr))72 def __isstr(self, s):73 try:74 return isinstance(s, basestring)75 except NameError:...
jsonlib.py
Source:jsonlib.py
1import json2class Json:3 def __init__(self):4 # Helper functions5 self.__isDict = lambda var: isinstance(var, dict)6 self.__isStr = lambda var: isinstance(var, str)7 def dumps(self, data):8 return json.dumps(data) if self.__isDict(data) else None9 def loads(self, data):10 return json.loads(data) if self.__isStr(data) else None11 def write(self, path, data):12 with open(path, 'w') as fd:13 return json.dump(data, fd) if self.__isDict(data) else True14 def read(self, path):15 with open(path, 'r') as fd:16 return json.load(fd)17 def append(self, path, data):18 with open(path, 'a') as fd:...
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!!