How to use visit_Assign method in avocado

Best Python code snippet using avocado_python

db_query_string_format_plugin_tests.py

Source:db_query_string_format_plugin_tests.py Github

copy

Full Screen

1import astroid2import pylint.testutils3from baseplate.lint import db_query_string_format_plugin4class TestNoCQLStringFormatChecker(pylint.testutils.CheckerTestCase):5 CHECKER_CLASS = db_query_string_format_plugin.NoDbQueryStringFormatChecker6 def test_finds_variable_binop_string_format_query(self):7 assign_node_a, call_node_b = astroid.extract_node(8 """9 query = "select * from %s" % "users" #@10 cassandra_session.execute(query) #@11 """12 )13 self.checker.visit_assign(assign_node_a)14 self.checker.visit_call(call_node_b)15 self.assertAddsMessages(16 pylint.testutils.Message(msg_id="database-query-string-format", node=call_node_b)17 )18 def test_finds_variable_call_string_format_query(self):19 assign_node_a, call_node_b = astroid.extract_node(20 """21 query = "select * from %s".format("users") #@22 cassandra_session.execute(query) #@23 """24 )25 self.checker.visit_assign(assign_node_a)26 self.checker.visit_call(call_node_b)27 self.assertAddsMessages(28 pylint.testutils.Message(msg_id="database-query-string-format", node=call_node_b)29 )30 def test_finds_binop_string_format_query(self):31 call_node_a = astroid.extract_node(32 """33 cassandra_session.execute("select * from %s" % "users") #@34 """35 )36 self.checker.visit_call(call_node_a)37 self.assertAddsMessages(38 pylint.testutils.Message(msg_id="database-query-string-format", node=call_node_a)39 )40 def test_finds_call_string_format_query(self):41 call_node_a = astroid.extract_node(42 """43 cassandra_session.execute("select * from %s".format("users")) #@44 """45 )46 self.checker.visit_call(call_node_a)47 self.assertAddsMessages(48 pylint.testutils.Message(msg_id="database-query-string-format", node=call_node_a)49 )50 def test_ignores_variable_non_string_format_query(self):51 assign_node_a, call_node_b = astroid.extract_node(52 """53 query = "select * from users" #@54 cassandra_session.execute(query) #@55 """56 )57 with self.assertNoMessages():58 self.checker.visit_assign(assign_node_a)59 self.checker.visit_call(call_node_b)60 def test_ignores_non_string_format_query(self):61 call_node_a = astroid.extract_node(62 """63 cassandra_session.execute("select * from users") #@64 """65 )66 with self.assertNoMessages():67 self.checker.visit_call(call_node_a)68 def test_ignores_no_argument(self):69 call_node_a = astroid.extract_node(70 """71 kb.execute() #@72 """73 )74 with self.assertNoMessages():75 self.checker.visit_call(call_node_a)76 def test_variable_reset(self):77 assign_node_a, assign_node_b, call_node_c = astroid.extract_node(78 """79 query = "select * from %s" % "users" #@80 query = "select * from users" #@81 cassandra_session.execute(query) #@82 """83 )84 with self.assertNoMessages():85 self.checker.visit_assign(assign_node_a)86 self.checker.visit_assign(assign_node_b)87 self.checker.visit_call(call_node_c)88 def test_func_variable_reset(self):89 func_node, assign_node_a, assign_node_b, call_node_c = astroid.extract_node(90 """91 def test(cassandra_session): #@92 query = "select * from %s" % "users" #@93 cassandra_session.execute(query)94 def other_test(cassandra_session):95 query = "select * from users" #@96 cassandra_session.execute(query) #@97 """98 )99 with self.assertNoMessages():100 self.checker.visit_assign(assign_node_a)101 self.checker.leave_functiondef(func_node)102 self.checker.visit_assign(assign_node_b)103 self.checker.visit_call(call_node_c)104 def test_class_variable_reset(self):105 class_node, assign_node_a, assign_node_b, call_node_c = astroid.extract_node(106 """107 class Test(): #@108 query = "select * from %s" % "users" #@109 cassandra_session.execute(query)110 query = "select * from users" #@111 cassandra_session.execute(query) #@112 """113 )114 with self.assertNoMessages():115 self.checker.visit_assign(assign_node_a)116 self.checker.leave_classdef(class_node)117 self.checker.visit_assign(assign_node_b)118 self.checker.visit_call(call_node_c)119 def test_module_variable_reset(self):120 mod_node, assign_node_a, assign_node_b, call_node_c = astroid.extract_node(121 """122 import test #@123 query = "select * from %s" % "users" #@124 cassandra_session.execute(query)125 import other_test126 query = "select * from users" #@127 cassandra_session.execute(query) #@128 """129 )130 with self.assertNoMessages():131 self.checker.visit_assign(assign_node_a)132 self.checker.leave_module(mod_node)133 self.checker.visit_assign(assign_node_b)...

Full Screen

Full Screen

example_plugin_tests.py

Source:example_plugin_tests.py Github

copy

Full Screen

1# Libraries needed for tests2import astroid3import pylint.testutils4from baseplate.lint import example_plugin5# CheckerTestCase creates a linter that will traverse the AST tree6class TestNoReassignmentChecker(pylint.testutils.CheckerTestCase):7 CHECKER_CLASS = example_plugin.NoReassignmentChecker8 # Use astroid.extract_node() to create a test case9 # Where you put #@ is where the variable gets assigned10 # example, assign_node_a = test = 1, assign_node_b = test = 211 def test_finds_reassigned_variable(self):12 assign_node_a, assign_node_b = astroid.extract_node(13 """14 test = 1 #@15 test = 2 #@16 """17 )18 self.checker.visit_assign(assign_node_a)19 self.checker.visit_assign(assign_node_b)20 self.assertAddsMessages(21 pylint.testutils.Message(msg_id="reassigned-variable", node=assign_node_a)22 )23 def test_ignores_no_reassigned_variable(self):24 assign_node_a, assign_node_b = astroid.extract_node(25 """26 test1 = 1 #@27 test2 = 2 #@28 """29 )30 with self.assertNoMessages():31 self.checker.visit_assign(assign_node_a)32 self.checker.visit_assign(assign_node_b)33 def test_ignores_variable_outside_function(self):34 func_node, assign_node_a, assign_node_b = astroid.extract_node(35 """36 def test1(): #@37 test = 1 #@38 def test2():39 test = 2 #@40 """41 )42 with self.assertNoMessages():43 self.checker.visit_assign(assign_node_a)44 self.checker.leave_functiondef(func_node)...

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