| 11 | |
| 12 | |
| 13 | class CodeVisitor(ast.NodeVisitor): |
| 14 | def __init__(self, code): |
| 15 | self.funcs = [] |
| 16 | self.func_names = [] |
| 17 | self.classes = [] |
| 18 | self.code = code |
| 19 | self.classname = "global" |
| 20 | self.has_class = False |
| 21 | self.has_input = False |
| 22 | self.only_func = False |
| 23 | self.all_func_in_class = False |
| 24 | |
| 25 | def visit_ClassDef(self, node): |
| 26 | self.classname = node.name |
| 27 | self.has_class = True |
| 28 | self.classes.append(node.name) |
| 29 | self.generic_visit(node) |
| 30 | self.classname = "global" |
| 31 | |
| 32 | def visit_Call(self, node): |
| 33 | if isinstance(node.func, ast.Name) and node.func.id == "input": |
| 34 | self.has_input = True |
| 35 | |
| 36 | self.generic_visit(node) |
| 37 | |
| 38 | def visit_FunctionDef(self, node): |
| 39 | self.func_names.append("{}@{}".format(node.name, self.classname)) |
| 40 | if self.classname == "global": |
| 41 | self.funcs.append(node.name) |
| 42 | self.generic_visit(node) |
| 43 | |
| 44 | def run(self): |
| 45 | self.root = ast.parse(self.code) |
| 46 | self.only_func = True |
| 47 | for statement in self.root.body: |
| 48 | if not isinstance(statement, ast.FunctionDef) and not isinstance(statement, ast.ClassDef): |
| 49 | self.only_func = False |
| 50 | break |
| 51 | self.visit(self.root) |
| 52 | |
| 53 | if len(self.classes) > 0 and len(self.func_names) > 0: |
| 54 | self.all_func_in_class = True |
| 55 | for f in self.func_names: |
| 56 | if f.split("@")[-1] == "global": |
| 57 | self.all_func_in_class = False |
| 58 | break |
| 59 | |
| 60 | class PlaceHolder(ast.NodeTransformer): |
| 61 | def __init__(self): |
no outgoing calls
no test coverage detected