How to use _get_relative_prefix method in avocado

Best Python code snippet using avocado_python

imported.py

Source:imported.py Github

copy

Full Screen

...120 if len(module_components) == 2:121 return (module_components[0], module_components[1])122 return ("", non_relative)123 @staticmethod124 def _get_relative_prefix(statement):125 """Returns the string that represents to the relative import level.126 :param statement: an "import from" ast statement127 :type statement: :class:`ast.ImportFrom`128 :returns: the string that represents the relative import level.129 :rtype: str130 """131 relative_level = getattr(statement, "level", 0) or 0132 return "".join(["." for _ in range(relative_level)])133 @staticmethod134 def get_symbol_from_statement(statement):135 return ImportedSymbol.get_symbol_module_path_from_statement(statement)[0]136 @staticmethod137 def get_module_path_from_statement(statement):138 return ImportedSymbol.get_symbol_module_path_from_statement(statement)[1]139 @staticmethod140 def get_symbol_module_path_from_statement(statement, name_index=0):141 symbol = ""142 module_path = ""143 module_alias = ""144 symbol_alias = ""145 import_as = get_statement_import_as(statement)146 names = list(import_as.keys())147 as_names = list(import_as.values())148 if isinstance(statement, ast.Import):149 # On an Import statement, it's impossible to import a symbol150 # so everything is the module_path151 module_path = names[name_index]152 module_alias = as_names[name_index]153 elif isinstance(statement, ast.ImportFrom):154 symbol = names[name_index]155 relative = ImportedSymbol._get_relative_prefix(statement)156 module_name = statement.module or ""157 module_path = relative + module_name158 symbol_alias = as_names[name_index]159 return symbol, module_path, module_alias, symbol_alias160 @property161 def module_name(self):162 """The final name of the module from its importer perspective.163 If a alias exists, it will be the alias name. If not, it will164 be the original name.165 """166 if self.module_alias:167 return self.module_alias168 return self.module_path169 @property...

Full Screen

Full Screen

test_safeloader_imported.py

Source:test_safeloader_imported.py Github

copy

Full Screen

...19 self.assertEqual(res, ("a.b.c", "d"))20class ModuleRelativePath(unittest.TestCase):21 def test_no_relative_import(self):22 statement = ast.parse("import os").body[0]23 self.assertEqual(ImportedSymbol._get_relative_prefix(statement), "")24 def test_no_relative_import_from(self):25 statement = ast.parse("from os import path").body[0]26 self.assertEqual(ImportedSymbol._get_relative_prefix(statement), "")27 def test_relative_import_from_upper(self):28 statement = ast.parse("from ..selftests import utils").body[0]29 self.assertEqual(ImportedSymbol._get_relative_prefix(statement), "..")30 def test_relative_import_from_same(self):31 statement = ast.parse("from .utils import function").body[0]32 self.assertEqual(ImportedSymbol._get_relative_prefix(statement), ".")33class SymbolAndModulePathCommon(unittest.TestCase):34 def _check_basic(self, input_module_path, input_symbol, input_statement):35 """Checks all but to_str(), returning the imported_symbol instance."""36 statement = ast.parse(input_statement).body[0]37 symbol = ImportedSymbol.get_symbol_from_statement(statement)38 msg = f'Expected symbol name "{input_symbol}", found "{symbol}"'39 self.assertEqual(symbol, input_symbol, msg)40 module_path = ImportedSymbol.get_module_path_from_statement(statement)41 msg = f'Expected module path "{input_module_path}", ' f'found "{module_path}"'42 self.assertEqual(module_path, input_module_path, msg)43 imported_symbol = ImportedSymbol(module_path, symbol)44 self.assertEqual(imported_symbol, ImportedSymbol.from_statement(statement))45 return imported_symbol46 def _check(self, input_module_path, input_symbol, *input_statements):...

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