Best Python code snippet using avocado_python
safeloader.py
Source:safeloader.py
...173 method_pattern.match(st.name)]174 methods = data_structures.ordered_list_unique(methods)175 result[statement.name] = methods176 return result177def get_methods_info(statement_body, class_tags):178 """179 Returns information on an Avocado instrumented test method180 """181 methods_info = []182 for st in statement_body:183 if (isinstance(st, ast.FunctionDef) and184 st.name.startswith('test')):185 docstring = ast.get_docstring(st)186 mt_tags = get_docstring_directives_tags(docstring)187 mt_tags.update(class_tags)188 methods = [method for method, _ in methods_info]189 if st.name not in methods:190 methods_info.append((st.name, mt_tags))191 return methods_info192def find_avocado_tests(path, class_name=None):193 """194 Attempts to find Avocado instrumented tests from Python source files195 :param path: path to a Python source code file196 :type path: str197 :param class_name: the specific class to be found198 :type path: str199 :returns: tuple where first item is dict with class name and additional200 info such as method names and tags; the second item is201 set of class names which look like avocado tests but are202 force-disabled.203 :rtype: tuple204 """205 module = AvocadoModule(path)206 # The resulting test classes207 result = collections.OrderedDict()208 disabled = set()209 for klass in module.iter_classes():210 # class_name will exist only under recursion. In that211 # case, we will only process the class if it has the212 # expected class_name.213 if class_name is not None and class_name != klass.name:214 continue215 docstring = ast.get_docstring(klass)216 # Looking for a class that has in the docstring either217 # ":avocado: enable" or ":avocado: disable218 has_disable = check_docstring_directive(docstring,219 'disable')220 if (has_disable and class_name is None):221 disabled.add(klass.name)222 continue223 cl_tags = get_docstring_directives_tags(docstring)224 has_enable = check_docstring_directive(docstring,225 'enable')226 if (has_enable and class_name is None):227 info = get_methods_info(klass.body, cl_tags)228 result[klass.name] = info229 continue230 # Looking for the 'recursive' docstring or a 'class_name'231 # (meaning we are under recursion)232 has_recurse = check_docstring_directive(docstring,233 'recursive')234 if (has_recurse or class_name is not None):235 info = get_methods_info(klass.body, cl_tags)236 result[klass.name] = info237 # Getting the list of parents of the current class238 parents = klass.bases239 # Searching the parents in the same module240 for parent in parents[:]:241 # Looking for a 'class FooTest(Parent)'242 if not isinstance(parent, ast.Name):243 # 'class FooTest(bar.Bar)' not supported withing244 # a module245 continue246 parent_class = parent.id247 res, dis = find_avocado_tests(path, parent_class)248 if res:249 parents.remove(parent)250 for cls in res:251 info.extend(res[cls])252 disabled.update(dis)253 # If there are parents left to be discovered, they254 # might be in a different module.255 for parent in parents:256 if isinstance(parent, ast.Attribute):257 # Looking for a 'class FooTest(module.Parent)'258 parent_module = parent.value.id259 parent_class = parent.attr260 else:261 # Looking for a 'class FooTest(Parent)'262 parent_module = None263 parent_class = parent.id264 for node in module.mod.body:265 reference = None266 # Looking for 'from parent import class'267 if isinstance(node, ast.ImportFrom):268 reference = parent_class269 # Looking for 'import parent'270 elif isinstance(node, ast.Import):271 reference = parent_module272 if reference is None:273 continue274 for artifact in node.names:275 # Looking for a class alias276 # ('from parent import class as alias')277 if artifact.asname is not None:278 parent_class = reference = artifact.name279 # If the parent class or the parent module280 # is found in the imports, discover the281 # parent module path and find the parent282 # class there283 if artifact.name == reference:284 modules_paths = [os.path.dirname(path)]285 modules_paths.extend(sys.path)286 if parent_module is None:287 parent_module = node.module288 _, ppath, _ = imp.find_module(parent_module,289 modules_paths)290 res, dis = find_avocado_tests(ppath,291 parent_class)292 if res:293 for cls in res:294 info.extend(res[cls])295 disabled.update(dis)296 continue297 # Looking for a 'class FooTest(Test):'298 if module.test_imports:299 base_ids = [base.id for base in klass.bases300 if isinstance(base, ast.Name)]301 # Looking for a 'class FooTest(Test):'302 if not module.test_imports.isdisjoint(base_ids):303 info = get_methods_info(klass.body,304 cl_tags)305 result[klass.name] = info306 continue307 # Looking for a 'class FooTest(avocado.Test):'308 if module.mod_imports:309 for base in klass.bases:310 if not isinstance(base, ast.Attribute):311 # Check only 'module.Class' bases312 continue313 cls_module = base.value.id314 cls_name = base.attr315 if cls_module in module.mod_imports and cls_name == 'Test':316 info = get_methods_info(klass.body,317 cl_tags)318 result[klass.name] = info319 continue...
apc.py
Source:apc.py
...120 def _methods(self, item=None):121 idx = 0122 print '\n'123 if item is not None:124 name, args, usage = self.get_methods_info(METHODS[item])125 print "[%3d] \001\033[35m\002%s\001\033[0m\002%s" % (item, name, args)126 if "Desc" in METHODS[item].keys():127 print "\n Desc :"128 for d in METHODS[item]["Desc"]:129 print " %s" % d130 if "Args" in METHODS[item].keys():131 print "\n Args :"132 for key,value in METHODS[item]["Args"].items():133 print " %s : %s" % (key, value)134 if "Usage" in METHODS[item].keys():135 print "\n Usage :"136 print " %s" % (METHODS[item]["Usage"])137 else:138 for m in METHODS:139 name, args, usage = self.get_methods_info(m)140 print "[%3d] \001\033[35m\002%40s\001\033[0m\002%s" % (idx, name, args)141 idx = idx + 1142 print '\n'143 def get_methods_info(self, methods):144 name = ""145 args = ""146 usage = ""147 if "Name" in methods:148 m = methods["Name"]149 if self.RE_PARSER_METHODS.match(m):150 name = self.RE_PARSER_METHODS.match(m).group(1)151 args = '(' + self.RE_PARSER_METHODS.match(m).group(2) + ')'152 else:153 name = m154 if "Usage" in methods:155 usage = methods["Usage"]156 return name,args,usage157 def set_context_to_native(self):...
plot_results.py
Source:plot_results.py
...37 # include_datasets=["NJUD"],38 # exclude_datasets=["LFSD"],39)40# å
å«ææå¾
æ¯è¾æ¨¡åç»æçä¿¡æ¯åç»å¾é
ç½®çåå
¸41drawing_info = get_methods_info(42 methods_info_json=data_info["method"],43 for_drawing=True,44 our_name="Ours",45 # include_methods=["CTMF_V16"],46 # exclude_methods=["UCNet_ABP"],47)48# ä¿åæ²çº¿ææ æ°æ®çæ件路å¾49curves_npy_path = os.path.join(output_path, data_type + "_" + "curves.npy")50# jsonä¸åå¨çæ¹æ³åå并ä¸æ¯æå®é
æ³è¦ç¨æ¥ä½ä¸ºå¾ä¾çååï¼è¿ééè¦ä¿®æ¹line_label51new_drawing_info = []52for method_name, method_info in drawing_info.items():53 label_name = method_info["curve_setting"]["line_label"]54 label_name = label_name.split("_")[0]55 method_info["curve_setting"]["line_label"] = label_name...
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!!