示例#1
0
import os
import sys

from NoneVisitor import *

dirName = '/Users/dillon/PythonWorkspace/'

x = NoneVisitor()
numExceptions = 0
for root, dirs, files in os.walk(dirName):
    for file in files:
        if file.endswith(".py"):
            path = os.path.join(root, file)
            print path
            try:
                parsedFile = ast.parse(open(path, "r").read())
                x.currentFile = path
                x.visit(parsedFile)
            except Exception, e:
                numExceptions += 1
                print 'Error: Could not parse file, exception: %s' % e

x.printErrors()
print ''
print 'Number of exceptions', numExceptions
示例#2
0
def twoErrors():
    fileName = './cases/Test2.py'
    parsedFile = ast.parse(open(fileName, 'r').read())
    x = NoneVisitor()
    x.visit(parsedFile)
    testAssert(x.numErrors() == 2, 'twoErrors')
示例#3
0
def setNone():
    fileName = './cases/Test3.py'
    parsedFile = ast.parse(open(fileName, 'r').read())
    x = NoneVisitor()
    x.visit(parsedFile)
    testAssert(x.numErrors() == 1, 'setNone')
示例#4
0
def basicTest():
    fileName = './cases/Test1.py'
    parsedFile = ast.parse(open(fileName, 'r').read())
    x = NoneVisitor()
    x.visit(parsedFile)
    testAssert(x.numErrors() == 1, 'basicTest')
示例#5
0
def countErrors(fileName):
    parsedFile = ast.parse(open(fileName, 'r').read())
    x = NoneVisitor()
    x.visit(parsedFile)
    return x.numErrors()