Commit b3bb4cea authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

New scripts folder to check the effectiveness of fixers

parent a2ab7763
These scripts are used to manually check that the fixers have not forgotten any
special cases, i.e. the implementation of their `match` method is good enough.
import ast, os, sys
class Analyzer(ast.NodeVisitor):
def __init__(self, file_path):
with open(file_path) as f:
source_code = f.read()
self.file_path = f.name
self.source_code = source_code.split('\n')
self.tree = ast.parse(source_code)
self.warnings = 0
def __call__(self):
self.visit(self.tree)
return self.warnings
def visit_BinOp(self, node):
if isinstance(node.op, ast.Div):
self.warnings += 1
print("%s:%s |%s" % (
self.file_path, node.lineno, self.source_code[node.lineno - 1]))
def analyze_file(file_path):
try:
analyzer = Analyzer(file_path)
except Exception as e:
print("Error: %s => %s" % (file_path, e))
return 0, 1
return analyzer(), 0
def analyze_dir(dir_path):
total_warnings = total_errors = 0
# Inspired by lib2to3
py_ext = os.extsep + "py"
for dirpath, dirnames, filenames in os.walk(dir_path):
for name in filenames:
if not name.startswith(".") and os.path.splitext(name)[1] == py_ext:
warnings, errors = analyze_file(os.path.join(dirpath, name))
total_warnings += warnings
total_errors += errors
return total_warnings, total_errors
def main():
for dir_or_file in sys.argv[1:]:
f = analyze_dir if os.path.isdir(dir_or_file) else analyze_file
print("%s warning(s), %s error(s)" % f(dir_or_file))
if __name__ == '__main__':
main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment