How to use get_symbol_from_statement method in avocado

Best Python code snippet using avocado_python

imported.py

Source: imported.py Github

copy

Full Screen

...130 """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):...

Full Screen

Full Screen

test_safeloader_imported.py

Source: test_safeloader_imported.py Github

copy

Full Screen

...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):47 statement_str_matches = []48 for input_statement in input_statements:49 imported_symbol = self._check_basic(50 input_module_path, input_symbol, input_statement51 )52 match = imported_symbol.to_str() == input_statement53 statement_str_matches.append(match)54 self.assertIn(True, statement_str_matches)55class SymbolAndModulePathImport(SymbolAndModulePathCommon):56 def test_symbol_only(self):57 self._check("os", "", "import os")58 def test_symbol_only_alias(self):59 self._check_basic("os", "", "import os as operatingsystem")60 def test_compound(self):61 self._check("os.path", "", "import os.path")62class SymbolAndModulePathImportFrom(SymbolAndModulePathCommon):63 def test_symbol_module_path(self):64 self._check("os", "path", "from os import path")65 def test_symbol_module_path_compound(self):66 self._check("unittest.mock", "mock_open", "from unittest.mock import mock_open")67 def test_symbol_module_path_only_relative(self):68 self._check("..", "utils", "from .. import utils")69 def test_symbol_module_path_from_relative(self):70 self._check("..selftests", "utils", "from ..selftests import utils")71 def test_symbol_module_path_from_relative_multiple(self):72 self._check("..selftests.utils", "mod", "from ..selftests.utils import mod")73class Alias(unittest.TestCase):74 def test_module_alias(self):75 statement = ast.parse("import os as operatingsystem").body[0]76 imported_symbol = ImportedSymbol.from_statement(statement)77 self.assertEqual(imported_symbol.module_path, "os")78 self.assertEqual(imported_symbol.module_name, "operatingsystem")79 def test_module_noalias(self):80 statement = ast.parse("import os").body[0]81 imported_symbol = ImportedSymbol.from_statement(statement)82 self.assertEqual(imported_symbol.module_path, "os")83 self.assertEqual(imported_symbol.module_name, "os")84 def test_symbol_alias(self):85 statement = ast.parse("from os import path as os_path").body[0]86 imported_symbol = ImportedSymbol.from_statement(statement)87 self.assertEqual(imported_symbol.symbol, "path")88 self.assertEqual(imported_symbol.symbol_name, "os_path")89 def test_symbol_noalias(self):90 statement = ast.parse("from os import path").body[0]91 imported_symbol = ImportedSymbol.from_statement(statement)92 self.assertEqual(imported_symbol.symbol, "path")93 self.assertEqual(imported_symbol.symbol_name, "path")94class SymbolAndModulePathErrors(unittest.TestCase):95 def test_incorrect_statement_type(self):96 statement = ast.parse("pass").body[0]97 with self.assertRaises(ValueError):98 _ = ImportedSymbol.get_symbol_from_statement(statement)99class RelativePath(unittest.TestCase):100 def test_same(self):101 imported_symbol = ImportedSymbol(102 ".module", "symbol", "/​abs/​fs/​location/​test.py"103 )104 self.assertEqual(105 imported_symbol.get_relative_module_fs_path(), "/​abs/​fs/​location"106 )107 def test_upper(self):108 imported_symbol = ImportedSymbol(109 "..module", "symbol", "/​abs/​fs/​location/​test.py"110 )111 self.assertEqual(imported_symbol.get_relative_module_fs_path(), "/​abs/​fs")112 def test_upper_from_statement(self):...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Nov’22 Updates: Live With Automation Testing On OTT Streaming Devices, Test On Samsung Galaxy Z Fold4, Galaxy Z Flip4, & More

Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.

Considering Agile Principles from a different angle

In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.

How To Choose The Best JavaScript Unit Testing Frameworks

JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.

How To Write End-To-End Tests Using Cypress App Actions

When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.

[LambdaTest Spartans Panel Discussion]: What Changed For Testing & QA Community And What Lies Ahead

The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.

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