How to use leave_functiondef method in Kiwi

Best Python code snippet using Kiwi_python

test_function_order_checker.py

Source:test_function_order_checker.py Github

copy

Full Screen

...13 """)14 with self.assertAddsMessages(pylint.testutils.Message(msg_id='wrong-function-order', node=first_node,15 ),):16 self.checker.visit_functiondef(first_node)17 self.checker.leave_functiondef(first_node)18 self.checker.visit_functiondef(second_node)19 self.checker.visit_call(call_node)20 self.checker.leave_functiondef(second_node)21 def test_function_order_when_caller_before_callee(self):22 first_node, call_node, second_node = astroid.extract_node("""23 def first(): #@24 second() #@25 def second(): #@26 pass27 """)28 with self.assertNoMessages():29 self.checker.visit_functiondef(first_node)30 self.checker.visit_call(call_node)31 self.checker.leave_functiondef(first_node)32 self.checker.visit_functiondef(second_node)33 self.checker.leave_functiondef(second_node)34 def test_method_order_when_caller_after_callee(self):35 first_node, second_node, call_node = astroid.extract_node("""36 class Foo:37 def first(self): #@38 pass39 def second(self): #@40 self.first() #@ """)41 with self.assertAddsMessages(pylint.testutils.Message(msg_id='wrong-method-order', node=first_node,42 ),):43 self.checker.visit_functiondef(first_node)44 self.checker.leave_functiondef(first_node)45 self.checker.visit_functiondef(second_node)46 self.checker.visit_call(call_node)47 self.checker.leave_functiondef(second_node)48 def test_method_order_when_caller_before_callee(self):49 first_node, call_node, second_node = astroid.extract_node("""50 class Foo:51 def first(self): #@52 self.second() #@53 def second(self): #@54 pass""")55 with self.assertNoMessages():56 self.checker.visit_functiondef(first_node)57 self.checker.visit_call(call_node)58 self.checker.leave_functiondef(first_node)59 self.checker.visit_functiondef(second_node)60 self.checker.leave_functiondef(second_node)61 def test_method_order_ignored_when_inner_function(self):62 first_node, second_node, call_node = astroid.extract_node("""63 class Foo:64 def outer(self): #@65 def inner(): #@66 return True67 inner() #@68 """)69 with self.assertNoMessages():70 self.checker.visit_functiondef(first_node)71 self.checker.visit_functiondef(second_node)72 self.checker.leave_functiondef(second_node)73 self.checker.visit_call(call_node)74 self.checker.leave_functiondef(first_node)75if __name__ == "__main__":...

Full Screen

Full Screen

replace_functions.py

Source:replace_functions.py Github

copy

Full Screen

1import argparse2from ast import Expression, literal_eval3from typing import Union4import libcst as cst5from libcst.codemod import CodemodContext, VisitorBasedCodemodCommand6from libcst.codemod.visitors import AddImportsVisitor7class ReplaceFunctionCommand(VisitorBasedCodemodCommand):8 # Add a description so that future codemodders can see what this does.9 DESCRIPTION: str = "Replaces the body of a function with pass."10 def __init__(self, context: CodemodContext) -> None:11 # Initialize the base class with context, and save our args. Remember, the12 # "dest" for each argument we added above must match a parameter name in13 # this init.14 super().__init__(context)15 def leave_FunctionDef(16 self, original_node: cst.FunctionDef, updated_node: cst.FunctionDef17 ) -> cst.FunctionDef:18 functions_docstring = updated_node.get_docstring()19 docstring_should_be = '"""No docstring here yet."""'20 if functions_docstring is not None:21 docstring_should_be = '"""\n{}\n\n"""'.format(functions_docstring)22 replace_function = cst.FunctionDef(23 name=updated_node.name,24 params=updated_node.params, # cst.Parameters(),25 body=cst.IndentedBlock(26 body=[27 cst.SimpleStatementLine(28 body=[29 cst.Expr(30 value=cst.SimpleString(31 value=docstring_should_be,32 lpar=[],33 rpar=[],34 ),35 semicolon=cst.MaybeSentinel.DEFAULT,36 ),37 ],38 leading_lines=[],39 trailing_whitespace=cst.TrailingWhitespace(40 whitespace=cst.SimpleWhitespace(41 value="",42 ),43 comment=None,44 newline=cst.Newline(45 value=None,46 ),47 ),48 ),49 cst.SimpleStatementLine(50 body=[51 cst.Pass(),52 ],53 ),54 ]55 ),56 )57 return replace_function58 def leave_ClassDef(59 self, original_node: cst.ClassDef, updated_node: cst.ClassDef60 ) -> cst.ClassDef:61 new_body = []62 for body_item in updated_node.body.body:63 if type(body_item) is cst.FunctionDef:64 new_body.append(self.leave_FunctionDef(body_item, body_item))65 return updated_node.with_changes(body=cst.IndentedBlock(new_body))66 def leave_Module(67 self, original_node: cst.Module, updated_node: cst.Module68 ) -> cst.Module:69 new_module_body = []70 for node in original_node.body:71 if type(node) is cst.FunctionDef:72 new_module_body.append(self.leave_FunctionDef(node, node))73 if type(node) is cst.ClassDef:74 new_module_body.append(self.leave_ClassDef(node, node))75 replace_function = cst.Module(body=new_module_body)...

Full Screen

Full Screen

test_defer_inlinecallbacks.py

Source:test_defer_inlinecallbacks.py Github

copy

Full Screen

...19 msg_id="does-not-produce-generator",20 node=function_node,21 ),22 ):23 self.checker.leave_functiondef(function_node)24 def test_is_generator(self):25 function_node = astroid.extract_node("""\26from twisted.internet import defer27@defer.inlineCallbacks28def foo():29 yield "bar"30""")31 with self.assertNoMessages():32 self.checker.leave_functiondef(function_node)33 def test_abstract_method(self):34 function_node = astroid.extract_node("""\35from twisted.internet import defer36from abc import abstractmethod37@abstractmethod38@defer.inlineCallbacks39def foo():40 return "bar"41""")42 with self.assertNoMessages():43 self.checker.leave_functiondef(function_node)44 def test_sub_definitions(self):45 function_node = astroid.extract_node("""\46from twisted.internet import defer47@defer.inlineCallbacks48def foo():49 @defer.inlineCallbacks50 def bar():51 yield "wibble"52 return bar()53""")54 with self.assertAddsMessages(55 Message(56 msg_id="does-not-produce-generator",57 node=function_node,58 ),59 ):...

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