Commit 024066ea authored by Daniel Smith's avatar Daniel Smith

Added ability to suppress console and/or file output

parent a742e9d5
Pipeline #1342 canceled with stages
......@@ -4,50 +4,73 @@ import re
failedTests = {} # Typing.dict()
totalCount = 0
totalTestCaseCount = 0
def findFailedTests(logfile: str):
global totalCount
pattern = re.compile(r'[0-9]{1,}(?<!0) failed')
global totalTestCaseCount
pattern = re.compile(r'[0-9]{1,}(?<!0) failed') # Look for the testresults line that includes the number of failed tests, where not 0.
with open(logfile) as log:
with open(logfile) as log: #Open the log file
logtext = log.read()
if pattern.search(logtext):
with open("{0}_failures.txt".format(logfile[:-4]), mode='w+') as outfile:
for match in pattern.finditer(logtext):
if pattern.search(logtext): # Find match(es) with the regex pattern above.
resultsFilename = "" # Typing.str()
if args.suppressFile:
resultsFilename = os.devnull
else:
resultsFilename = "{0}{1}{2}_failures.txt".format(os.path.join(args.logDir, "parser_results"), os.sep,
logfile[logfile.rfind(os.sep) + 1: logfile.rfind('.txt')])
with open(resultsFilename, mode='w+') as outfile:
for match in pattern.finditer(logtext): # Iterate through the matches for failed tests and strip out the individual cases.
tstnameindex = 0
tstnameindex = logtext.rfind("********* Start testing of ", 0, match.span()[0]) + 27
tstnameindex = logtext.rfind("********* Start testing of ", 0, match.span()[0]) + 27 # Search for the test case.
tstname = logtext[tstnameindex:
logtext.find("*********", tstnameindex)-1]
print("{0}: {1}".format(tstname,match.group(0))) # Print the test name and count failed.
outfile.writelines("{0}: {1}\r\n".format(tstname,match.group(0)))
logtext.find("*********", tstnameindex)-1]
if not args.suppressConsole:
print("{0}: {1}".format(tstname,match.group(0))) # Print the test name and count failed.
outfile.writelines("{0}: {1}\r\n".format(tstname,match.group(0))) # Write it to file.
if int(re.match(r'[0-9]{0,}', match.group(0)).group(0)) > 9:
if int(re.match(r'[0-9]{0,}', match.group(0)).group(0)) > 9 and not args.printAll: #
outfile.writelines("Too many fail cases. Not printing the failures here. See the original log for failure details.")
print("Too many fail cases. Not printing the failures here. See the original log for failure details.")
if not args.suppressConsole:
print("Too many fail cases. Not printing the failures here. See the original log for failure details.")
break
logsnip = logtext[tstnameindex : logtext.find("********* Finished testing of ", tstnameindex)]
logsnip = logtext[tstnameindex : logtext.find("********* Finished testing of ", tstnameindex)] # Save a snip of the log with the failed test(s)
for failcasematch in re.finditer('FAIL! : ', logsnip):
for failcasematch in re.finditer('FAIL! : ', logsnip): # Find the actual fail case
totalTestCaseCount += 1
# Look for the end of the case. We know coin always print the file location. Grab up the the newline when we find that.
failcasestring = logsnip[failcasematch.span()[0] : logsnip.find('\n', logsnip.find("Loc: ", failcasematch.span()[0]))]
print("{0}\r\n".format(failcasestring))
if not args.suppressConsole:
print("{0}\r\n".format(failcasestring))
outfile.writelines("{0}\r\n".format(failcasestring))
totalCount += 1
print("\r\n")
if not args.suppressConsole: print("\r\n") # just a spacer fore readability when printing results to screen.
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--logdir',dest='logDir', type=str,
required=True, help='The full path to a directory of logs')
parser.add_argument('--logdir',dest='logDir', type=str, required=True, help='The full path to a directory of logs')
parser.add_argument('--printall', action='store_true', dest="printAll", help="Set --printall to force printing details of tests with more than 9 fail cases. ")
parser.add_argument('--suppressconsole', action='store_true', dest="suppressConsole", help="Set --supressconsole to prevent writing to screen.")
parser.add_argument('--suppressfile', action='store_true', dest="suppressFile", help="Set --supressfile to prevent writing results to file.")
args = parser.parse_args()
logfiles = os.listdir(args.logDir)
print(logfiles)
# print(logfiles) # diagnostic
if not os.path.exists(os.path.join(args.logDir, "parser_results")) and not args.suppressFile:
os.makedirs(os.path.join(args.logDir, "parser_results"))
for logfile in logfiles:
print(logfile)
findFailedTests(os.path.join(args.logDir, logfile))
print("Processing {0}".format(logfile))
if not os.path.isdir(os.path.join(args.logDir, logfile)):
findFailedTests(os.path.join(args.logDir, logfile))
print("total failed test applications: {0}".format(totalCount))
\ No newline at end of file
print("Done parsing.\r\nTotal failed test applications: {0}\r\nTotal failed test cases: {1}".format(totalCount, totalTestCaseCount))
\ No newline at end of file
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