How to use get_importable_spec method in avocado

Best Python code snippet using avocado_python

core.py

Source:core.py Github

copy

Full Screen

...214 parent_class,215 imported_symbol,216 symbol_is_module,217 ) = _get_attributes_for_further_examination(parent, module)218 found_spec = imported_symbol.get_importable_spec(symbol_is_module)219 if found_spec is None:220 continue221 except ClassNotSuitable:222 continue223 _info, _disabled, _match = _examine_class(224 target_module,225 target_class,226 determine_match,227 found_spec.origin,228 parent_class,229 match,230 )231 if _info:232 _extend_test_list(info, _info)233 disabled.update(_disabled)234 if _match is not match:235 match = _match236 if not match and module.interesting_klass_found:237 imported_symbol = module.imported_symbols[class_name]238 if imported_symbol:239 found_spec = imported_symbol.get_importable_spec()240 if found_spec:241 _info, _disabled, _match = _examine_class(242 target_module,243 target_class,244 determine_match,245 found_spec.origin,246 class_name,247 match,248 )249 if _info:250 _extend_test_list(info, _info)251 disabled.update(_disabled)252 if _match is not match:253 match = _match254 return info, disabled, match255def find_python_tests(target_module, target_class, determine_match, path):256 """257 Attempts to find Python tests from source files258 A Python test in this context is a method within a specific type259 of class (or that inherits from a specific class).260 :param target_module: the name of the module from which a class should261 have come from. When attempting to find a Python262 unittest, the target_module will most probably263 be "unittest", as per the standard library module264 name. When attempting to find Avocado tests, the265 target_module will most probably be "avocado".266 :type target_module: str267 :param target_class: the name of the class that is considered to contain268 test methods. When attempting to find Python269 unittests, the target_class will most probably be270 "TestCase". When attempting to find Avocado tests,271 the target_class will most probably be "Test".272 :type target_class: str273 :type determine_match: a callable that will determine if a given module274 and class is contains valid Python tests275 :type determine_match: function276 :param path: path to a Python source code file277 :type path: str278 :returns: tuple where first item is dict with class name and additional279 info such as method names and tags; the second item is280 set of class names which look like Python tests but have been281 forcefully disabled.282 :rtype: tuple283 """284 module = PythonModule(path, target_module, target_class)285 # The resulting test classes286 result = collections.OrderedDict()287 disabled = set()288 for klass in module.iter_classes():289 docstring = ast.get_docstring(klass)290 # Looking for a class that has in the docstring either291 # ":avocado: enable" or ":avocado: disable292 if check_docstring_directive(docstring, "disable"):293 disabled.add(klass.name)294 continue295 if check_docstring_directive(docstring, "enable"):296 info = get_methods_info(297 klass.body,298 get_docstring_directives_tags(docstring),299 get_docstring_directives_dependencies(docstring),300 )301 result[klass.name] = info302 continue303 # From this point onwards we want to do recursive discovery, but304 # for now we don't know whether it is avocado.Test inherited305 # (Ifs are optimized for readability, not speed)306 # If "recursive" tag is specified, it is forced as test307 if check_docstring_directive(docstring, "recursive"):308 match = True309 else:310 match = module.is_matching_klass(klass)311 info = get_methods_info(312 klass.body,313 get_docstring_directives_tags(docstring),314 get_docstring_directives_dependencies(docstring),315 )316 # Getting the list of parents of the current class317 parents = klass.bases318 match = _examine_same_module(319 parents,320 info,321 disabled,322 match,323 module,324 target_module,325 target_class,326 determine_match,327 )328 # If there are parents left to be discovered, they329 # might be in a different module.330 for parent in parents:331 try:332 (333 parent_class,334 imported_symbol,335 symbol_is_module,336 ) = _get_attributes_for_further_examination(parent, module)337 found_spec = imported_symbol.get_importable_spec(symbol_is_module)338 if found_spec is None:339 continue340 except ClassNotSuitable:341 continue342 _info, _dis, _match = _examine_class(343 target_module,344 target_class,345 determine_match,346 found_spec.origin,347 parent_class,348 match,349 )350 if _info:351 info.extend(_info)...

Full Screen

Full Screen

imported.py

Source:imported.py Github

copy

Full Screen

...70 previous = components[index - 1]71 else:72 previous = ""73 yield (component, previous)74 def get_importable_spec(self, symbol_is_module=False):75 """Returns the specification of an actual importable module.76 This is a check based on the limitations that we do not77 actually perform an import, and assumes a directory structure78 with modules.79 :param symbol_is_module: if it's known that the symbol is also80 a module, include it in the search for81 an importable spec82 :type symbol_is_module: bool83 """84 modules_paths = sys.path85 modules_paths.insert(0, self.get_relative_module_fs_path())86 spec = None87 for component, previous in self._walk_importable_components(symbol_is_module):88 if previous:89 modules_paths = [90 os.path.join(mod, previous) for mod in modules_paths[:]91 ]92 spec = PathFinder.find_spec(component, modules_paths)93 if spec is None:94 break95 return spec96 def is_importable(self, symbol_is_module=False):97 """Checks whether this imported symbol seems to be importable.98 This is a check based on the limitations that we do not99 actually perform an import, and assumes a directory structure100 with modules.101 :param symbol_is_module: if it's known that the symbol is also102 a module, include it in the search for103 an importable spec104 :type symbol_is_module: bool105 """106 return self.get_importable_spec(symbol_is_module) is not None107 @staticmethod108 def _split_last_module_path_component(module_path):109 """Splits a module path into a lower and topmost components.110 It also discards any information about relative location.111 :param module_path: a module path, such as "os" or "os.path"112 or "..selftests.utils"113 :type module_path: str114 :returns: the lower and topmost components115 :rtype: tuple116 """117 non_relative = module_path.strip(".")118 if "." in non_relative:119 module_components = non_relative.rsplit(".", 1)120 if len(module_components) == 2:...

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 avocado 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