def testFunctionDefWithBody(self): expected_string = """def testFunc(): a""" expected_node = GetNodeFromInput(expected_string) test_node = create_node.FunctionDef( 'testFunc', body=[create_node.Expr(create_node.Name('a'))]) self.assertNodesEqual(expected_node, test_node)
def testFunctionDefWithNameKwargs(self): expected_string = """def testFunc(a=b, c=d): pass""" expected_node = GetNodeFromInput(expected_string) test_node = create_node.FunctionDef( 'testFunc', keys=['a', 'c'], values=[create_node.Name('b'), create_node.Name('d')]) self.assertNodesEqual(expected_node, test_node)
def testDecoratorList(self): expected_string = """@decorator @other_decorator(arg) def testFunc(**kwargs): pass""" expected_node = GetNodeFromInput(expected_string) test_node = create_node.FunctionDef('testFunc', kwarg_name='kwargs', decorator_list=[ create_node.Name('decorator'), create_node.Call( 'other_decorator', args=['arg']) ]) self.assertNodesEqual(expected_node, test_node)
def testFunctionDefWithKwarg(self): expected_string = """def testFunc(**kwargs): pass""" expected_node = GetNodeFromInput(expected_string) test_node = create_node.FunctionDef('testFunc', kwarg_name='kwargs') self.assertNodesEqual(expected_node, test_node)
def testFunctionDefWithArgs(self): expected_string = """def testFunc(a, b): pass""" expected_node = GetNodeFromInput(expected_string) test_node = create_node.FunctionDef('testFunc', args=('a', 'b')) self.assertNodesEqual(expected_node, test_node)