How to use get_statement_import_as method in avocado

Best Python code snippet using avocado_python

module.py

Source: module.py Github

copy

Full Screen

...108 if interesting_klass in [name.name for name in statement.names]:109 self.interesting_klass_found = True110 if statement.module != self.module:111 return112 name = get_statement_import_as(statement).get(self.klass, None)113 if name is not None:114 self.klass_imports.add(name)115 @staticmethod116 def _all_module_level_names(full_module_name):117 result = []118 components = full_module_name.split(".")[:-1]119 for topmost in range(len(components)):120 result.append(".".join(components[-topmost:]))121 components.pop()122 return result123 def _handle_import(self, statement):124 self.add_imported_symbol(statement)125 imported_as = get_statement_import_as(statement)126 name = imported_as.get(self.module, None)127 if name is not None:128 self.mod_imports.add(name)129 for as_name in imported_as.values():130 for mod_name in self._all_module_level_names(as_name):131 if mod_name == self.module:132 self.mod_imports.add(mod_name)133 def iter_classes(self, interesting_klass=None):134 """135 Iterate through classes and keep track of imported avocado statements136 """137 for statement in self.mod.body:138 # Looking for a 'from <module> import <klass>'139 if isinstance(statement, ast.ImportFrom):...

Full Screen

Full Screen

test_safeloader_utils.py

Source: test_safeloader_utils.py Github

copy

Full Screen

...4from avocado.core.safeloader.utils import get_statement_import_as5class StatementImportAs(unittest.TestCase):6 def test_import(self):7 statement = ast.parse("import os").body[0]8 self.assertEqual({"os": "os"}, get_statement_import_as(statement))9 def test_import_alias(self):10 statement = ast.parse("import os as operatingsystem").body[0]11 self.assertEqual({"os": "operatingsystem"}, get_statement_import_as(statement))12 def test_import_from(self):13 statement = ast.parse("from os import path").body[0]14 self.assertEqual({"path": "path"}, get_statement_import_as(statement))15 def test_import_from_alias(self):16 statement = ast.parse("from os import path as stdlibpath").body[0]17 self.assertEqual({"path": "stdlibpath"}, get_statement_import_as(statement))18 def test_import_order(self):19 statement = ast.parse("import z, a").body[0]20 self.assertEqual(21 collections.OrderedDict({"z": "z", "a": "a"}),22 get_statement_import_as(statement),23 )24 def test_incorrect_statement_type(self):25 statement = ast.parse("pass").body[0]26 with self.assertRaises(ValueError):...

Full Screen

Full Screen

utils.py

Source: utils.py Github

copy

Full Screen

1import ast2import collections3def get_statement_import_as(statement):4 """5 Returns a mapping of imported module names whether using aliases or not6 :param statement: an AST import statement7 :type statement: ast.Import8 :returns: a mapping of names {<realname>: <alias>} of modules imported9 :rtype: collections.OrderedDict10 """11 if not any(12 [isinstance(statement, ast.Import), isinstance(statement, ast.ImportFrom)]13 ):14 raise ValueError("Value given is not an ast import or " "import from statement")15 result = collections.OrderedDict()16 for name in statement.names:17 if name.asname is not None:...

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, &#038; 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 &#038; 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