Best Python code snippet using robotframework-pageobjects_python
generate_ref.py
Source:generate_ref.py
...21 value = defaults[arg_index - args_with_no_defaults]22 if (type(value) is str):23 value = '"%s"' % value24 return DefaultArgSpec(True, value)25def get_method_sig(method):26 """ Given a function, it returns a string that pretty much looks how the27 function signature would be written in python.28 :param method: a python method29 :return: A string similar describing the pythong method signature.30 eg: "my_method(first_argArg, second_arg=42, third_arg='something')"31 """32 # The return value of ArgSpec is a bit weird, as the list of arguments and33 # list of defaults are returned in separate array.34 # eg: ArgSpec(args=['first_arg', 'second_arg', 'third_arg'],35 # varargs=None, keywords=None, defaults=(42, 'something'))36 argspec = inspect.getargspec(method)37 arg_index=038 args = []39 # Use the args and defaults array returned by argspec and find out40 # which arguments has default41 for arg in argspec.args:42 default_arg = _get_default_arg(argspec.args, argspec.defaults, arg_index)43 if default_arg.has_default:44 val = default_arg.default_value45 args.append("%s=%s" % (arg, val))46 else:47 args.append(arg)48 arg_index += 149 if argspec.varargs:50 args.append('*' + argspec.varargs)51 if argspec.keywords:52 args.append('**' + argspec.keywords)53 return "%s(%s)" % (method.__name__, ", ".join(args[1:]))54def docstring(obj):55 doc = (obj.__doc__ or '').rstrip()56 if doc:57 lines = doc.split('\n')58 # Find the length of the whitespace prefix common to all non-empty lines59 indentation = min(len(line) - len(line.lstrip()) for line in lines if line.strip())60 # Output the lines without the indentation61 for line in lines:62 print(line[indentation:])63 print()64def class_doc(cls, list_methods=True):65 bases = ', '.join([b.__name__ for b in cls.__bases__])66 print('###', cls.__name__)67 print()68 if bases != 'object':69 print('Extends', bases)70 print()71 docstring(cls)72 for name, method in inspect.getmembers(cls, lambda m: inspect.ismethod(m) or inspect.isfunction(m)):73 if name == '__init__':74 # Initializer75 print('####', get_method_sig(method).replace(name, cls.__name__))76 elif name[0] == '_':77 # Private method78 continue79 elif hasattr(method, '__self__') and method.__self__ == cls:80 # Class method81 if not list_methods:82 continue83 print('#### %s.%s' % (cls.__name__, get_method_sig(method)))84 else:85 # Regular method86 if not list_methods:87 continue88 print('####', get_method_sig(method))89 print()90 docstring(method)91 print()92def module_doc(classes, list_methods=True):93 mdl = classes[0].__module__94 print(mdl)95 print('-' * len(mdl))96 print()97 for cls in classes:98 class_doc(cls, list_methods)99def all_subclasses(cls):100 return cls.__subclasses__() + [g for s in cls.__subclasses__() for g in all_subclasses(s)]101if __name__ == '__main__':102 from infi.clickhouse_orm import database...
get_help.py
Source:get_help.py
...12 value = defaults[arg_index - args_with_no_defaults]13 if (type(value) is str):14 value = '"%s"' % value15 return DefaultArgSpec(True, value)16def get_method_sig(method):17 argspec = inspect.getargspec(method)18 arg_index=019 args = []20 for arg in argspec.args:21 default_arg = _get_default_arg(argspec.args, argspec.defaults, arg_index)22 if default_arg.has_default:23 args.append("%s=%s" % (arg, default_arg.default_value))24 else:25 args.append(arg)26 arg_index += 127 return "%s(%s)" % (method.__name__, ", ".join(args))28if __name__ == "__main__":29 lng = ix.api.ModuleLanguage.get_language(ix.application, 'Python')30 cmd = lng.get_help()31 help = ""32 try:33 if cmd != "" and cmd.startswith("ix"):34 modules = cmd.split(".")35 for part in modules:36 if modules.index(part) == 0:37 attr = sys.modules[part]38 else:39 attr = getattr(attr, part)40 method_sig = get_method_sig(attr)41 if attr.__doc__:42 # if the doc have more one line, put the signature before the doc43 if (attr.__doc__.count("\n") >= 1):44 help += method_sig45 help += "\n"46 help += attr.__doc__47 else:48 help += method_sig49 except:50 pass51 lng.set_help(help)...
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!!