diff --git a/bddtests/steps/coverage.py b/bddtests/steps/coverage.py index 850de1caa61..79f495ed058 100644 --- a/bddtests/steps/coverage.py +++ b/bddtests/steps/coverage.py @@ -8,19 +8,19 @@ def testCoverage(): - #First save the coverage files - saveCoverageFiles("coverage","scenario_1", ["bddtests_vp0_1","bddtests_vp1_1","bddtests_vp2_1","bddtests_vp3_1",], "cov") + #First save the coverage files + saveCoverageFiles("coverage","scenario_1", ["bddtests_vp0_1","bddtests_vp1_1","bddtests_vp2_1","bddtests_vp3_1",], "cov") # Now collect the filenames for coverage files. - files = glob.glob(os.path.join('coverage','*.cov')) + files = glob.glob(os.path.join('coverage','*.cov')) #Create the aggregate coverage file - coverageContents = createCoverageFile(files) + coverageContents = createCoverageFile(files) #Ouput the aggregate coverage file - with open('coverage.total', 'w') as outfile: - outfile.write(coverageContents) - outfile.close() + with open('coverage.total', 'w') as outfile: + outfile.write(coverageContents) + outfile.close() def createCoverageAggregate(): # Now collect the filenames for coverage files. @@ -39,10 +39,10 @@ def saveCoverageFiles(folderName, rootName, containerNames, extension): 'Will save the converage files to folderName' # Make the directory try: - os.makedirs(folderName) + os.makedirs(folderName) except OSError as exception: - if exception.errno != errno.EEXIST: - raise + if exception.errno != errno.EEXIST: + raise for containerName in containerNames: srcPath = "{0}:/opt/gopath/src/github.com/hyperledger/fabric/coverage.cov".format(containerName) print("sourcepath = {0}".format(srcPath)) @@ -68,27 +68,27 @@ def createCoverageFile(filenames): #with open('coverage.total', 'w') as outfile: for fname in filenames: with open(fname) as infile: - firstLine = True - for line in infile: - if firstLine: - firstLine = False - continue - else: - # Split the line based upon white space - lineParts = line.split() - if lineParts[0] in linesMap: - # Found, keep the greater - newCount = long(lineParts[2]) - oldCount = long(linesMap[lineParts[0]].split()[2]) - if newCount > oldCount: - linesMap[lineParts[0]] = line - else: - linesMap[lineParts[0]] = line + firstLine = True + for line in infile: + if firstLine: + firstLine = False + continue + else: + # Split the line based upon white space + lineParts = line.split() + if lineParts[0] in linesMap: + # Found, keep the greater + newCount = long(lineParts[2]) + oldCount = long(linesMap[lineParts[0]].split()[2]) + if newCount > oldCount: + linesMap[lineParts[0]] = line + else: + linesMap[lineParts[0]] = line # Now sort the output od = OrderedDict(sorted(linesMap.items(), key=lambda i: i[1])) for (key, line) in od.items(): - output.write(line) + output.write(line) contents = output.getvalue() output.close() return contents