How to use visit_ClassDef method in lisa

Best Python code snippet using lisa_python

test_checkers.py

Source:test_checkers.py Github

copy

Full Screen

1import astroid2import pylint_unittest3import pylint.testutils4class TestUniqueReturnChecker(pylint.testutils.CheckerTestCase):5 CHECKER_CLASS = pylint_unittest.checkers.UnittestAssertionsChecker6 def test_assertEqual_true(self):7 class_node, assert_node = astroid.extract_node("""8 import unittest9 class Tests(unittest.TestCase): #@10 def test_foo():11 self.assertEqual(a, True) #@12 """)13 with self.assertAddsMessages(14 pylint.testutils.Message(15 msg_id='wrong-assert',16 args=('assertTrue(x) or assertIs(x, True)', 'assertEqual(x, True)'),17 node=assert_node,18 ),19 ):20 self.checker.visit_classdef(class_node)21 self.checker.visit_call(assert_node)22 self.checker.leave_classdef(class_node)23 def test_assertEqual_false(self):24 class_node, assert_node = astroid.extract_node("""25 import unittest26 class Tests(unittest.TestCase): #@27 def test_foo():28 self.assertEqual(a, False) #@29 """)30 with self.assertAddsMessages(31 pylint.testutils.Message(32 msg_id='wrong-assert',33 args=('assertFalse(x) or assertIs(x, False)', 'assertEqual(x, False)',),34 node=assert_node,35 ),36 ):37 self.checker.visit_classdef(class_node)38 self.checker.visit_call(assert_node)39 self.checker.leave_classdef(class_node)40 def test_assertEqual_none(self):41 class_node, assert_node = astroid.extract_node("""42 import unittest43 class Tests(unittest.TestCase): #@44 def test_foo():45 self.assertEqual(a, None) #@46 """)47 with self.assertAddsMessages(48 pylint.testutils.Message(49 msg_id='wrong-assert',50 args=('assertIsNone(x)', 'assertEqual(x, None)',),51 node=assert_node,52 ),53 ):54 self.checker.visit_classdef(class_node)55 self.checker.visit_call(assert_node)56 self.checker.leave_classdef(class_node)57 def test_assertIs_none(self):58 class_node, assert_node = astroid.extract_node("""59 import unittest60 class Tests(unittest.TestCase): #@61 def test_foo():62 self.assertIs(a, None) #@63 """)64 with self.assertAddsMessages(65 pylint.testutils.Message(66 msg_id='wrong-assert',67 args=('assertIsNone(x)', 'assertEqual(x, None)'),68 node=assert_node,69 ),70 ):71 self.checker.visit_classdef(class_node)72 self.checker.visit_call(assert_node)73 self.checker.leave_classdef(class_node)74 def test_works_with_TestCase_subclasses(self):75 class_node, assert_node = astroid.extract_node("""76 import unittest77 class BaseTestCase(unittest.TestCase):78 pass79 class Tests(BaseTestCase): #@80 def test_foo():81 self.assertEqual(a, True) #@82 """)83 with self.assertAddsMessages(84 pylint.testutils.Message(85 msg_id='wrong-assert',86 args=('assertTrue(x) or assertIs(x, True)', 'assertEqual(x, True)'),87 node=assert_node,88 ),89 ):90 self.checker.visit_classdef(class_node)91 self.checker.visit_call(assert_node)92 self.checker.leave_classdef(class_node)93 def test_ignores_non_TestCase_subclasses(self):94 class_node, assert_node = astroid.extract_node("""95 class Tests(object): #@96 def test_foo():97 self.assertEqual(a, True) #@98 """)99 with self.assertNoMessages():100 self.checker.visit_classdef(class_node)101 self.checker.visit_call(assert_node)102 self.checker.leave_classdef(class_node)103 def test_deprecated_alias(self):104 class_node, assert_node = astroid.extract_node("""105 import unittest106 class Tests(unittest.TestCase): #@107 def test_foo():108 self.failIfEqual(a, None) #@109 """)110 with self.assertAddsMessages(111 pylint.testutils.Message(112 msg_id='deprecated-unittest-alias',113 args=('failIfEqual', 'assertNotEqual'),114 node=assert_node,115 ),116 ):117 self.checker.visit_classdef(class_node)118 self.checker.visit_call(assert_node)119 self.checker.leave_classdef(class_node)120 def test_isinstance(self):121 class_node, assert_node = astroid.extract_node("""122 import unittest123 class Tests(unittest.TestCase): #@124 def test_foo():125 self.assertTrue(isinstance(a, Class)) #@126 """)127 with self.assertAddsMessages(128 pylint.testutils.Message(129 msg_id='wrong-assert',130 args=('assertIsInstance(x, Class)', 'assertTrue(isinstance(x, Class))'),131 node=assert_node,132 ),133 ):134 self.checker.visit_classdef(class_node)135 self.checker.visit_call(assert_node)136 self.checker.leave_classdef(class_node)137 def test_isinstance_does_not_fail_with_other_expression(self):138 class_node, assert_node = astroid.extract_node("""139 import unittest140 class Tests(unittest.TestCase): #@141 def test_foo():142 form = Form()143 self.assertTrue(form.is_valid()) #@144 """)145 with self.assertNoMessages():146 self.checker.visit_classdef(class_node)147 self.checker.visit_call(assert_node)148 self.checker.leave_classdef(class_node)149 def test_isnotinstance(self):150 class_node, assert_node = astroid.extract_node("""151 import unittest152 class Tests(unittest.TestCase): #@153 def test_foo():154 self.assertFalse(isinstance(a, Class)) #@155 """)156 with self.assertAddsMessages(157 pylint.testutils.Message(158 msg_id='wrong-assert',159 args=('assertIsNotInstance(x, Class)', 'assertFalse(isinstance(x, Class))'),160 node=assert_node,161 ),162 ):163 self.checker.visit_classdef(class_node)164 self.checker.visit_call(assert_node)...

Full Screen

Full Screen

handle_by_tree.py

Source:handle_by_tree.py Github

copy

Full Screen

...14 classes = [n for n in self.node.body if isinstance(n, ast.ClassDef)] 15 return functions, classes 16class ClassAttributeVisitor:17 def __init__(self, class_node):18 self.class_attrs = self.visit_ClassDef(class_node)19 def visit_ClassDef(self, node):20 lst = []21 body = node.body 22 for statement in body:23 if isinstance(statement, ast.Assign):24 if len(statement.targets) == 1:25 value = statement.value26 value = self._check_type(value)27 lst.append((statement.targets[0].id, value))28 return lst29 30 def _check_type(self, value):31 if isinstance(value, ast.Call):32 if isinstance(value.func, ast.Attribute):33 value = value.func.attr34 elif isinstance(value.func, ast.Name):35 value = value.func.id36 elif isinstance(value, ast.List):37 value = [e.s for e in value.elts]38 elif isinstance(value, ast.Constant):39 value = value.s40 elif isinstance(value, ast.Name):41 value = value.id42 return value43if __name__ == '__main__':44 f = ast.parse(open('D:\\Software Structure Generator\\test_files\\app\\api\\models.py', 'r').read())45 # print(dir(ast.Call))46 class_def = [n for n in f.body if isinstance(n, ast.ClassDef)]47 print(ClassAttributeVisitor().visit_ClassDef(class_def[0]))48 49 ...

Full Screen

Full Screen

django_rest_framework.py

Source:django_rest_framework.py Github

copy

Full Screen

1from astroid.nodes import Class2from pylint.checkers.base import DocStringChecker3from pylint.checkers.classes import ClassChecker4from pylint.checkers.design_analysis import MisdesignChecker5from pylint.checkers.newstyle import NewStyleConflictChecker6from pylint_django.utils import node_is_subclass7from pylint_plugin_utils import suppress_message8def is_class(class_name):9 """Shortcut for node_is_subclass."""10 return lambda node: node_is_subclass(node, class_name)11def is_model_meta_subclass(node):12 """Checks that node is derivative of Meta class."""13 if node.name != 'Meta' or not isinstance(node.parent, Class):14 return False15 parents = ('rest_framework.views.APIView',16 'django_filters.filterset.FilterSet',17 'rest_framework.serializers.ModelSerializer')18 return any([node_is_subclass(node.parent, parent) for parent in parents])19def apply_augmentations(linter):20 # Suppress the no __init__ method message21 for clazz in ["django_filters.filterset.FilterSet"]:22 suppress_message(linter, ClassChecker.visit_classdef, 'W0232', is_class(clazz))23 suppress_message(linter, DocStringChecker.visit_classdef, 'C0111', is_class('django_filters.filterset.FilterSet'))24 # Meta25 suppress_message(linter, DocStringChecker.visit_classdef, 'C0111', is_model_meta_subclass)26 suppress_message(linter, NewStyleConflictChecker.visit_classdef, 'C1001', is_model_meta_subclass)27 suppress_message(linter, ClassChecker.visit_classdef, 'W0232', is_model_meta_subclass)...

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