Fix python print

This commit is contained in:
Malcolm Noyes 2014-03-10 12:37:47 +00:00
parent 7a6a230f74
commit a0c5242d8b
1 changed files with 47 additions and 47 deletions

View File

@ -32,7 +32,7 @@ else:
else: else:
cmdPath = os.path.join( catchPath, 'projects/XCode4/CatchSelfTest/DerivedData/CatchSelfTest/Build/Products/Debug/CatchSelfTest' ) cmdPath = os.path.join( catchPath, 'projects/XCode4/CatchSelfTest/DerivedData/CatchSelfTest/Build/Products/Debug/CatchSelfTest' )
print cmdPath print( cmdPath )
overallResult = 0 overallResult = 0
@ -60,7 +60,7 @@ def approve( baseName, args ):
if os.path.exists( rawResultsPath ): if os.path.exists( rawResultsPath ):
resultFileHandler = TestRunResultHandler(rawResultsPath) resultFileHandler = TestRunResultHandler(rawResultsPath)
#rawPathNew = os.path.join( rootPath, '{0}.rewrite.txt'.format( baseName ) ) #rawPathNew = os.path.join( rootPath, '{0}.rewrite.txt'.format( baseName ) )
#print "F:",rawPathNew,",",approvedFileHandler.current.outputLine #print( "F:" + rawPathNew," + ",approvedFileHandler.current.outputLine )
#resultFileHandler.writeRawFile(rawPathNew) #resultFileHandler.writeRawFile(rawPathNew)
rawPathNewSorted = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format( baseName ) ) rawPathNewSorted = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format( baseName ) )
resultFileHandler.writeSortedUnapprovedFile(rawPathNewSorted, approvedFileHandler.current.outputLine) resultFileHandler.writeSortedUnapprovedFile(rawPathNewSorted, approvedFileHandler.current.outputLine)
@ -70,25 +70,25 @@ def approve( baseName, args ):
def callDiff(): def callDiff():
#os.remove( rawResultsPath ) #os.remove( rawResultsPath )
print print()
print baseName + ":" print( baseName + ":" )
if os.path.exists( baselinesSortedPath ) and os.path.exists( rawPathNewSorted ): if os.path.exists( baselinesSortedPath ) and os.path.exists( rawPathNewSorted ):
diffResult = subprocess.call([ "diff", "--ignore-all-space", baselinesSortedPath, rawPathNewSorted ] ) diffResult = subprocess.call([ "diff", "--ignore-all-space", baselinesSortedPath, rawPathNewSorted ] )
if diffResult == 0: if diffResult == 0:
#os.remove( filteredResultsPath ) #os.remove( filteredResultsPath )
if not(sys.platform == 'win32'): if not(sys.platform == 'win32'):
print " \033[92mResults matched" print( " \033[92mResults matched" )
else: else:
print " Results matched" print( " Results matched" )
else: else:
if not(sys.platform == 'win32'): if not(sys.platform == 'win32'):
print " \n****************************\n \033[91mResults differed" print( " \n****************************\n \033[91mResults differed" )
else: else:
print " \n****************************\n Results differed" print( " \n****************************\n Results differed" )
if diffResult > overallResult: if diffResult > overallResult:
overallResult = diffResult overallResult = diffResult
if not(sys.platform == 'win32'): if not(sys.platform == 'win32'):
print "\033[0m" print( "\033[0m" )
def approveJunit( baseName, args ): def approveJunit( baseName, args ):
global overallResult global overallResult
@ -123,7 +123,7 @@ def approveJunit( baseName, args ):
for tc in testsuites: for tc in testsuites:
if tc.tag == "testcase": if tc.tag == "testcase":
cls = tc.get("classname") cls = tc.get("classname")
#print "C:",cls,tc #print( "C:" + cls + tc )
if len(cls): if len(cls):
testcase = testRun.addClassTestCase(cls, tc.get("name")) testcase = testRun.addClassTestCase(cls, tc.get("name"))
else: else:
@ -174,13 +174,13 @@ def approveJunit( baseName, args ):
lines = text.splitlines() lines = text.splitlines()
testRun.addSyserr(lines) testRun.addSyserr(lines)
else: else:
print tc.tag print( tc.tag )
lines = testRun.generateSortedUnapprovedJunit() lines = testRun.generateSortedUnapprovedJunit()
rawWriteFile = open( baselinesSortedPath, 'wb' ) rawWriteFile = open( baselinesSortedPath, 'wb' )
for line in lines: for line in lines:
#print "L:",line #print( "L:" + line )
rawWriteFile.write(line + "\n") rawWriteFile.write(line + "\n")
rawWriteFile.close() rawWriteFile.close()
@ -215,7 +215,7 @@ def approveJunit( baseName, args ):
for tc in testsuites: for tc in testsuites:
if tc.tag == "testcase": if tc.tag == "testcase":
cls = tc.get("classname") cls = tc.get("classname")
#print "C:",cls,tc #print( "C:" + cls + tc )
if len(cls): if len(cls):
if cls.startswith("::"): if cls.startswith("::"):
cls = cls[2:] cls = cls[2:]
@ -268,13 +268,13 @@ def approveJunit( baseName, args ):
lines = text.splitlines() lines = text.splitlines()
testRun.addSyserr(lines) testRun.addSyserr(lines)
else: else:
print tc.tag print( tc.tag )
lines = testRun.generateSortedUnapprovedJunit() lines = testRun.generateSortedUnapprovedJunit()
rawWriteFile = open( rawSortedPath, 'wb' ) rawWriteFile = open( rawSortedPath, 'wb' )
for line in lines: for line in lines:
#print "L:",line #print( "L:" + line )
rawWriteFile.write(line + "\n") rawWriteFile.write(line + "\n")
rawWriteFile.close() rawWriteFile.close()
@ -304,7 +304,7 @@ def addSubSection(testcase, section, exp):
ls = text.splitlines() ls = text.splitlines()
testcase.addSubFailure(section, ls) testcase.addSubFailure(section, ls)
elif tmp.tag == "Expression": elif tmp.tag == "Expression":
#print "Exp:",tmp #print( "Exp:" + tmp )
e1 = True e1 = True
result = tmp.get("success") result = tmp.get("success")
filename = tmp.get("filename") filename = tmp.get("filename")
@ -325,13 +325,13 @@ def addSubSection(testcase, section, exp):
ls = text.splitlines() ls = text.splitlines()
subExp.append(ls) subExp.append(ls)
else: else:
print "SX:",cond.tag print( "SX:" + cond.tag )
if len(subExp) >= 2: if len(subExp) >= 2:
testcase.addExpressionDetails(subSection, subExp) testcase.addExpressionDetails(subSection, subExp)
else: else:
print "Z:",tmp.tag print( "Z:" + tmp.tag )
#if e1: #if e1:
# print "Section:",section # print( "Section:" + section )
def addResultsSubSection(otherResultsTestParser, testcase, section, exp): def addResultsSubSection(otherResultsTestParser, testcase, section, exp):
r = exp.find("OverallResults") r = exp.find("OverallResults")
@ -362,7 +362,7 @@ def addResultsSubSection(otherResultsTestParser, testcase, section, exp):
ls = text.splitlines() ls = text.splitlines()
testcase.addSubFailure(section, ls) testcase.addSubFailure(section, ls)
elif tmp.tag == "Expression": elif tmp.tag == "Expression":
#print "Exp:",tmp #print( "Exp:" + tmp )
e1 = True e1 = True
result = tmp.get("success") result = tmp.get("success")
filename = tmp.get("filename") filename = tmp.get("filename")
@ -390,13 +390,13 @@ def addResultsSubSection(otherResultsTestParser, testcase, section, exp):
ls = text.splitlines() ls = text.splitlines()
subExp.append(ls) subExp.append(ls)
else: else:
print "SX:",cond.tag print( "SX:" + cond.tag )
if len(subExp) >= 2: if len(subExp) >= 2:
testcase.addExpressionDetails(subSection, subExp) testcase.addExpressionDetails(subSection, subExp)
else: else:
print "Z:",tmp.tag print( "Z:" + tmp.tag )
#if e1: #if e1:
# print "Section:",section # print( "Section:" + section )
def approveXml( baseName, args ): def approveXml( baseName, args ):
global overallResult global overallResult
@ -418,7 +418,7 @@ def approveXml( baseName, args ):
root = etree.fromstring(xml) root = etree.fromstring(xml)
testRun.appname = root.get("name") testRun.appname = root.get("name")
for ts in root: for ts in root:
#print ts.tag #print( ts.tag )
for tc in ts: for tc in ts:
if tc.tag == "TestCase": if tc.tag == "TestCase":
testcase = testRun.addTestCase(tc.get("name")) testcase = testRun.addTestCase(tc.get("name"))
@ -443,7 +443,7 @@ def approveXml( baseName, args ):
ls = text.splitlines() ls = text.splitlines()
subExp.append(ls) subExp.append(ls)
else: else:
print "X:",cond.tag print( "X:" + cond.tag )
if len(subExp) >= 2: if len(subExp) >= 2:
testcase.addExpressionDetails(section, subExp) testcase.addExpressionDetails(section, subExp)
elif exp.tag == "Exception": elif exp.tag == "Exception":
@ -470,18 +470,18 @@ def approveXml( baseName, args ):
elif exp.tag == "OverallResult": elif exp.tag == "OverallResult":
testcase.addOverallResult(exp.get("success")) testcase.addOverallResult(exp.get("success"))
else: else:
print "E:",exp.tag print( "E:" + exp.tag )
elif tc.tag == "OverallResults": elif tc.tag == "OverallResults":
testRun.tests = tc.get("successes") testRun.tests = tc.get("successes")
testRun.failures = tc.get("failures") testRun.failures = tc.get("failures")
else: else:
print "U:",tc.tag print( "U:" + tc.tag )
lines = testRun.generateSortedUnapprovedXml() lines = testRun.generateSortedUnapprovedXml()
rawWriteFile = open( baselinesSortedPath, 'wb' ) rawWriteFile = open( baselinesSortedPath, 'wb' )
for line in lines: for line in lines:
#print "L:",line #print( "L:" + line )
rawWriteFile.write(line + "\n") rawWriteFile.write(line + "\n")
rawWriteFile.close() rawWriteFile.close()
@ -511,7 +511,7 @@ def approveXml( baseName, args ):
if testRun.appname == "TestCatch.exe": if testRun.appname == "TestCatch.exe":
testRun.appname = "CatchSelfTest" testRun.appname = "CatchSelfTest"
for ts in root: for ts in root:
#print ts.tag #print( ts.tag )
for tc in ts: for tc in ts:
if tc.tag == "TestCase": if tc.tag == "TestCase":
testcase = testRun.addTestCase(tc.get("name")) testcase = testRun.addTestCase(tc.get("name"))
@ -533,7 +533,7 @@ def approveXml( baseName, args ):
m = hexParser.match(li) m = hexParser.match(li)
if m: if m:
while m: while m:
#print li, m.group(1), m.group(3) #print( li + m.group(1) + m.group(3) )
li = m.group(1) + "0x<hex digits>" + m.group(3) li = m.group(1) + "0x<hex digits>" + m.group(3)
m = hexParser.match(li) m = hexParser.match(li)
ls.append(li) ls.append(li)
@ -546,7 +546,7 @@ def approveXml( baseName, args ):
m = hexParser.match(li) m = hexParser.match(li)
if m: if m:
while m: while m:
#print li, m.group(1), m.group(3) #print( li + m.group(1) + m.group(3) )
li = m.group(1) + "0x<hex digits>" + m.group(3) li = m.group(1) + "0x<hex digits>" + m.group(3)
m = hexParser.match(li) m = hexParser.match(li)
ls.append(li) ls.append(li)
@ -561,7 +561,7 @@ def approveXml( baseName, args ):
ls = text.splitlines() ls = text.splitlines()
subExp.append(ls) subExp.append(ls)
else: else:
print "X:",cond.tag print( "X:" + cond.tag )
if len(subExp) >= 2: if len(subExp) >= 2:
testcase.addExpressionDetails(section, subExp) testcase.addExpressionDetails(section, subExp)
elif exp.tag == "Exception": elif exp.tag == "Exception":
@ -591,23 +591,23 @@ def approveXml( baseName, args ):
elif exp.tag == "OverallResult": elif exp.tag == "OverallResult":
testcase.addOverallResult(exp.get("success")) testcase.addOverallResult(exp.get("success"))
else: else:
print "E:",exp.tag print( "E:" + exp.tag )
elif tc.tag == "OverallResults": elif tc.tag == "OverallResults":
testRun.tests = tc.get("successes") testRun.tests = tc.get("successes")
testRun.failures = tc.get("failures") testRun.failures = tc.get("failures")
else: else:
print "U:",tc.tag print( "U:" + tc.tag )
lines = testRun.generateSortedUnapprovedXml() lines = testRun.generateSortedUnapprovedXml()
rawWriteFile = open( rawSortedPath, 'wb' ) rawWriteFile = open( rawSortedPath, 'wb' )
for line in lines: for line in lines:
#print "L:",line #print( "L:" + line )
rawWriteFile.write(line + "\n") rawWriteFile.write(line + "\n")
rawWriteFile.close() rawWriteFile.close()
def parseTrxFile(baseName, trxFile): def parseTrxFile(baseName, trxFile):
print "TRX file:" ,trxFile print( "TRX file:" + trxFile )
if os.path.exists( trxFile ): if os.path.exists( trxFile ):
xml = "" xml = ""
f = open( trxFile, 'r' ) f = open( trxFile, 'r' )
@ -627,7 +627,7 @@ def parseTrxFile(baseName, trxFile):
m = qname.match(ts.tag) m = qname.match(ts.tag)
if m: if m:
tag = m.group(2) tag = m.group(2)
print tag print( tag )
if tag != None: if tag != None:
if tag == "TestDefinitions": if tag == "TestDefinitions":
for tc in ts: for tc in ts:
@ -643,12 +643,12 @@ def parseTrxFile(baseName, trxFile):
tag = m.group(2) tag = m.group(2)
if tag != None and tag == "Description": if tag != None and tag == "Description":
desc = item.text desc = item.text
#print desc, id #print( desc + id )
ids.append([id,desc]) ids.append([id,desc])
elif tag == "Results": elif tag == "Results":
#print ids #print( ids )
ids = dict(ids) ids = dict(ids)
#print ids["87ec526a-e414-1a3f-ba0f-e210b204bb42"] #print( ids["87ec526a-e414-1a3f-ba0f-e210b204bb42"] )
lineNumber = 0 lineNumber = 0
resultParser = TestCaseResultParser() resultParser = TestCaseResultParser()
@ -682,8 +682,8 @@ def parseTrxFile(baseName, trxFile):
break break
index += 1 index += 1
lines = lines[index + 3:] lines = lines[index + 3:]
#print "*******",desc #print( "*******" + desc )
#print lines #print( lines )
if found: if found:
endOfRun = False endOfRun = False
for line in lines: for line in lines:
@ -693,7 +693,7 @@ def parseTrxFile(baseName, trxFile):
try: try:
testcase = resultParser.parseResultLine(line) testcase = resultParser.parseResultLine(line)
except RandomOutput as e: except RandomOutput as e:
#print "E:", self.lineNumber, ", ",e.output #print( "E:" + self.lineNumber + ", " + e.output )
testRun.output = e.output testRun.output = e.output
testRun.outputLine = lineNumber - len(e.output) testRun.outputLine = lineNumber - len(e.output)
if isinstance(testcase, TestCaseData): if isinstance(testcase, TestCaseData):
@ -706,7 +706,7 @@ def parseTrxFile(baseName, trxFile):
rawSortedPath = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format( baseName ) ) rawSortedPath = os.path.join( rootPath, '{0}.sorted.unapproved.txt'.format( baseName ) )
rawWriteFile = open( rawSortedPath, 'wb' ) rawWriteFile = open( rawSortedPath, 'wb' )
for line in lines: for line in lines:
#print "L:",line #print( "L:" + line )
rawWriteFile.write(line + "\n") rawWriteFile.write(line + "\n")
rawWriteFile.close() rawWriteFile.close()
@ -734,7 +734,7 @@ def approveMsTest( baseName, filter ):
#args.append(dllPath) #args.append(dllPath)
#args.append("/TestCaseFilter:Owner=" + filter) #args.append("/TestCaseFilter:Owner=" + filter)
#print args #print( args )
f = open( rawResultsPath, 'w' ) f = open( rawResultsPath, 'w' )
subprocess.call( args, stdout=f, stderr=f ) subprocess.call( args, stdout=f, stderr=f )
f.close() f.close()
@ -763,6 +763,6 @@ approveMsTest( "mstest.std", "all")
approveMsTest( "mstest.sw", "allSucceeding") approveMsTest( "mstest.sw", "allSucceeding")
approveMsTest( "mstest.swa4", "allSucceedingAborting") approveMsTest( "mstest.swa4", "allSucceedingAborting")
if overallResult <> 0: if overallResult != 0:
print "run approve.py to approve new baselines" print( "run approve.py to approve new baselines" )
exit( overallResult) exit( overallResult)