示例#1
0
def gradeAndPrint(targets, testDirs=[], problemsOnly=False, prefix=""):
    filesAndTests = getFilesAndTests(targets, testDirs)
    newGCovResults = map(
        lambda fileAndTestFile: GCov.getCoverage(fileAndTestFile[1]),
        filesAndTests)

    summarys = GCov.computeSummary(filesAndTests, newGCovResults)
    if len(summarys) < 1:
        print "%sNo GCov Results - Please be sure to run 'make check' first" % prefix
        return False
    summarys = GCovSummary.removeTestSourceFiles(summarys)

    paths = summarys.keys()
    if problemsOnly:
        paths = filter(lambda key: summarys[key]["coverage"] < 100, paths)

    distribution = [99, 90]
    maximumFileLength = max(
        map(lambda entry: len(os.path.relpath(entry)), paths))
    format = "%s%-" + str(maximumFileLength) + "s %6s"
    print format % (prefix, "File Path", "Score")
    format = "%s%-" + str(maximumFileLength) + "s %6.2f"
    for path in sorted(paths):
        string = format % (prefix, os.path.relpath(path),
                           summarys[path]["coverage"])
        LongBow.scorePrinter(distribution, summarys[path]["coverage"], string)

    return True
示例#2
0
def commandLineMain(args, fileNames, testDir=""):

    testDirs = []
    if testDir:
        testDirs.append(testDir)
    fileNames = map(lambda fileName: os.path.abspath(fileName), fileNames)
    filesAndTests = map(
        lambda fileName: [fileName,
                          findTestExecutable(fileName, testDirs)], fileNames)

    filesWithNoTest = filter(lambda fileAndTest: fileAndTest[1] == None,
                             filesAndTests)
    if len(filesWithNoTest) != 0:
        outputFormat = "%s has no corresponding test executable or coverage data.\n"
        map(
            lambda filesAndTests: sys.stderr.write(outputFormat %
                                                   (filesAndTests[0])),
            filesWithNoTest)

    gCovResults = map(
        lambda fileAndTestFile: GCov.getCoverage(fileAndTestFile[1]),
        filesAndTests)

    if args.summary is True:
        displaySummary(args, filesAndTests, gCovResults)
    elif args.average is True:
        displayAverage(args, filesAndTests, gCovResults)
    elif args.visual is True:
        textVisual(args, filesAndTests, gCovResults)
    elif args.explain is True:
        explain(args, filesAndTests, gCovResults)

    return True
示例#3
0
def commandLineMain(args, fileNames, testDir=""):

    testDirs = []
    if testDir:
        testDirs.append(testDir)
    fileNames = map(lambda fileName: os.path.abspath(fileName), fileNames)
    filesAndTests = map(lambda fileName: [fileName, findTestExecutable(fileName, testDirs)], fileNames)

    filesWithNoTest = filter(lambda fileAndTest: fileAndTest[1] == None, filesAndTests)
    if len(filesWithNoTest) != 0:
        outputFormat = "%s has no corresponding test executable or coverage data.\n"
        map(lambda filesAndTests: sys.stderr.write(outputFormat % (filesAndTests[0])), filesWithNoTest)

    gCovResults = map(lambda fileAndTestFile: GCov.getCoverage(fileAndTestFile[1]), filesAndTests)

    if args.summary is True:
        displaySummary(args, filesAndTests, gCovResults)
    elif args.average is True:
        displayAverage(args, filesAndTests, gCovResults)
    elif args.visual is True:
        textVisual(args, filesAndTests, gCovResults)
    elif args.explain is True:
        explain(args, filesAndTests, gCovResults)

    return True
示例#4
0
def textSummary(args, filesAndTests, gCovResults, prefix=""):

    summary = GCov.computeSummary(filesAndTests, gCovResults)

    if not args.includeTestSources:
        summary = GCovSummary.removeTestSourceFiles(summary)

    if len(summary) == 0:
        return

    if args.explain:
        pp = pprint.PrettyPrinter(indent=2, width=150)
        pp.pprint(summary)

    maximumFileLength = max(map(lambda entry: len(entry), summary))

    format = "%s%-" + str(maximumFileLength) + "s %6s"
    print format % (prefix, "File Path", "Score")

    format = "%s%-" + str(maximumFileLength) + "s %6.2f"
    for testedFile in sorted(summary.keys()):
        string = format % (prefix, testedFile, summary[testedFile]["coverage"])
        if summary[testedFile]["direct"] == "indirect":
            ANSITerm.printColorized("magenta", string)
        else:
            LongBow.scorePrinter(eval(args.distribution),
                                 summary[testedFile]["coverage"], string)

    return
示例#5
0
def textSummary(args, filesAndTests, gCovResults, prefix=""):

    summary = GCov.computeSummary(filesAndTests, gCovResults)

    if not args.includeTestSources:
        summary = GCovSummary.removeTestSourceFiles(summary)

    if len(summary) == 0:
        return

    if args.explain:
        pp = pprint.PrettyPrinter(indent=2, width=150)
        pp.pprint(summary)

    maximumFileLength = max(map(lambda entry: len(entry), summary))

    format = "%s%-" + str(maximumFileLength) + "s %6s"
    print format % (prefix, "File Path", "Score")

    format = "%s%-" + str(maximumFileLength) + "s %6.2f"
    for testedFile in sorted(summary.keys()):
        string = format % (prefix, testedFile, summary[testedFile]["coverage"])
        if summary[testedFile]["direct"] == "indirect":
            ANSITerm.printColorized("magenta", string)
        else:
            LongBow.scorePrinter(eval(args.distribution), summary[testedFile]["coverage"], string)

    return
示例#6
0
def csvAverage(args, filesAndTests, gcovResults):
    summary = GCov.computeSummary(filesAndTests, gcovResults)

    if not args.includeTestSources:
        summary = GCovSummary.removeTestSourceFiles(summary)

    score = GCovSummary.averageCoverage(summary)

    LongBow.scorePrinter(eval(args.distribution), score, "%.2f" % (score))
    return
示例#7
0
def csvAverage(args, filesAndTests, gcovResults):
    summary = GCov.computeSummary(filesAndTests, gcovResults)

    if not args.includeTestSources:
        summary = GCovSummary.removeTestSourceFiles(summary)

    score = GCovSummary.averageCoverage(summary)

    LongBow.scorePrinter(eval(args.distribution), score, "%.2f" % (score))
    return
示例#8
0
def csvSummary(args, filesAndTests, gCovResults):
    summary = GCov.computeSummary(filesAndTests, gCovResults)

    if not args.includeTestSources:
        summary = GCovSummary.removeTestSourceFiles(summary)

    if len(summary) > 0:
        for testedFile in sorted(summary.keys()):
            outputString = "%s,%.2f" % (testedFile, summary[testedFile]["coverage"])
            LongBow.scorePrinter(eval(args.distribution), summary[testedFile]["coverage"], outputString)

    return
示例#9
0
def csvSummary(args, filesAndTests, gCovResults):
    summary = GCov.computeSummary(filesAndTests, gCovResults)

    if not args.includeTestSources:
        summary = GCovSummary.removeTestSourceFiles(summary)

    if len(summary) > 0:
        for testedFile in sorted(summary.keys()):
            outputString = "%s,%.2f" % (testedFile, summary[testedFile]["coverage"])
            LongBow.scorePrinter(eval(args.distribution), summary[testedFile]["coverage"], outputString)

    return
示例#10
0
def gradeAndPrint(targets, testDirs=[], problemsOnly=False, prefix=""):
    filesAndTests = getFilesAndTests(targets, testDirs)
    newGCovResults = map(lambda fileAndTestFile: GCov.getCoverage(fileAndTestFile[1]), filesAndTests)

    summarys = GCov.computeSummary(filesAndTests, newGCovResults)
    if len(summarys) < 1:
        print "%sNo GCov Results - Please be sure to run 'make check' first" % prefix
        return False
    summarys = GCovSummary.removeTestSourceFiles(summarys)

    paths = summarys.keys()
    if problemsOnly:
        paths = filter(lambda key: summarys[key]["coverage"] < 100, paths)

    distribution=[99,90]
    maximumFileLength = max(map(lambda entry: len(os.path.relpath(entry)), paths))
    format = "%s%-" + str(maximumFileLength) + "s %6s"
    print format % (prefix, "File Path", "Score")
    format = "%s%-" + str(maximumFileLength) + "s %6.2f"
    for path in sorted(paths):
        string = format % (prefix, os.path.relpath(path), summarys[path]["coverage"])
        LongBow.scorePrinter(distribution, summarys[path]["coverage"], string)

    return True
示例#11
0
def textVisual(args, filesAndTests, gcovResults):

    summary = GCov.computeSummary(filesAndTests, gcovResults)
    if args.explain:
        pp = pprint.PrettyPrinter(indent=2, width=150)
        pp.pprint(summary)
        pp.pprint(filesAndTests)

    for entry in filesAndTests:
        print entry[0]
        try:
            gcovLines = summary[entry[0]]["gcovLines"]
            map(lambda line: textVisualDisplayGcovLine(line.strip()), gcovLines)
        except KeyError:
            print >> sys.stderr, "No coverage information for", entry[0]

    return
示例#12
0
def textVisual(args, filesAndTests, gcovResults):

    summary = GCov.computeSummary(filesAndTests, gcovResults)
    if args.explain:
        pp = pprint.PrettyPrinter(indent=2, width=150)
        pp.pprint(summary)
        pp.pprint(filesAndTests)

    for entry in filesAndTests:
        print entry[0]
        try:
            gcovLines = summary[entry[0]]["gcovLines"]
            map(lambda line: textVisualDisplayGcovLine(line.strip()), gcovLines)
        except KeyError:
            print >> sys.stderr, "No coverage information for", entry[0]

    return