custom_rules.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:warriorframework 作者: warriorframework 项目源码 文件源码
def func_check(node, kw=False):
    '''
    Function specific check
        Action - check return type
        Action - check pstep/psubstep buddy with report_step/report_substep_status
        check docstring
        check print statement - should use print_utils
        scan for class - class check
        scan for function - recursive function check
    '''
    status = True
    have_return = False
    substep_count = 0

    # investigate everything in a function
    for child in ast.walk(node):
        if child != node and isinstance(child, ast.FunctionDef):
            # check for private method in action file
            if kw and child.name.startswith("_"):
                print node.name, child.name, "should move to utils"
                status = False
            tmp_status = func_check(child, kw)
            status &= tmp_status
        elif child != node and isinstance(child, ast.ClassDef):
            tmp_status = class_check(child, kw)
            status &= tmp_status
        elif 'war_print_class.py' not in sys.argv[1] and isinstance(child, ast.Print):
            # check for print statement
            status = False
            print "Please use print_Utils instead of print in {}: {}".format(
                                                    sys.argv[1], child.lineno)
        elif isinstance(child, ast.Return):
            # check for return statement
            have_return = True
        elif isinstance(child, ast.Attribute) and child.attr == 'pSubStep':
            # check for Substep and report substep pair
            substep_count += 1
        elif isinstance(child, ast.Attribute) and child.attr == 'report_substep_status':
            substep_count -= 1

    if ast.get_docstring(node) is None:
        print node.name, "doesn't contain any docstring"
        status = False
    if kw and not have_return and node.name != "__init__":
        print node.name, "doesn't contain a return statement"
        status = False
    if kw and substep_count:
        print node.name, "have non-pair pSubStepreport_substep_status"
        status = False
    return status
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号