mirror of
https://github.com/holub/mame
synced 2025-04-24 17:30:55 +03:00
chdtest.py: Python 3 compat. (nw)
This commit is contained in:
parent
be5f14c495
commit
196e21d88d
@ -7,6 +7,10 @@ import shutil
|
||||
def runProcess(cmd):
|
||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdout, stderr) = process.communicate()
|
||||
if not isinstance(stdout, str): # python 3
|
||||
stdout = stdout.decode('latin-1')
|
||||
if not isinstance(stderr, str): # python 3
|
||||
stderr = stderr.decode('latin-1')
|
||||
return process.returncode, stdout, stderr
|
||||
|
||||
def compareInfo(info1, info2):
|
||||
@ -23,7 +27,7 @@ def compareInfo(info1, info2):
|
||||
continue
|
||||
if not lines1[i] == lines2[i]:
|
||||
mismatch = True
|
||||
print lines1[i] + " - " + lines2[i]
|
||||
print(lines1[i] + " - " + lines2[i])
|
||||
|
||||
return mismatch == False
|
||||
|
||||
@ -54,7 +58,7 @@ def extractcdAndCompare(type):
|
||||
|
||||
exitcode, stdout, stderr = runProcess([chdmanBin, "extractcd", "-f", "-i", outFile, "-o", extractFile])
|
||||
if not exitcode == 0:
|
||||
print d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
|
||||
sha1_extract = sha1sum(extractFile)
|
||||
@ -69,20 +73,20 @@ def extractcdAndCompare(type):
|
||||
|
||||
exitcode, stdout, stderr = runProcess([chdmanBin, "extractcd", "-f", "-i", tempFile, "-o", extractFile])
|
||||
if not exitcode == 0:
|
||||
print d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
|
||||
sha1_extract_2 = sha1sum(extractFile)
|
||||
sha1_extract_bin_2 = sha1sum(extractFileBin)
|
||||
|
||||
if not sha1_extract == sha1_extract_2:
|
||||
print "expected: " + sha1_extract + " found: " + sha1_extract_2
|
||||
print d + " - SHA1 mismatch (extractcd - " + type + " - toc)"
|
||||
print("expected: " + sha1_extract + " found: " + sha1_extract_2)
|
||||
print(d + " - SHA1 mismatch (extractcd - " + type + " - toc)")
|
||||
failure = True
|
||||
|
||||
if not sha1_extract_bin == sha1_extract_bin_2:
|
||||
print "expected: " + sha1_extract_bin + " found: " + sha1_extract_bin_2
|
||||
print d + " - SHA1 mismatch (extractcd - " + type + " - bin)"
|
||||
print("expected: " + sha1_extract_bin + " found: " + sha1_extract_bin_2)
|
||||
print(d + " - SHA1 mismatch (extractcd - " + type + " - bin)")
|
||||
failure = True
|
||||
|
||||
def extractAndCompare(command, ext):
|
||||
@ -95,7 +99,7 @@ def extractAndCompare(command, ext):
|
||||
|
||||
exitcode, stdout, stderr = runProcess([chdmanBin, command, "-f", "-i", outFile, "-o", extractFile])
|
||||
if not exitcode == 0:
|
||||
print d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
|
||||
sha1_extract = sha1sum(extractFile)
|
||||
@ -108,14 +112,14 @@ def extractAndCompare(command, ext):
|
||||
|
||||
exitcode, stdout, stderr = runProcess([chdmanBin, command, "-f", "-i", tempFile, "-o", extractFile])
|
||||
if not exitcode == 0:
|
||||
print d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
|
||||
sha1_extract_2 = sha1sum(extractFile)
|
||||
|
||||
if not sha1_extract == sha1_extract_2:
|
||||
print "expected: " + sha1_extract + " found: " + sha1_extract_2
|
||||
print d + " - SHA1 mismatch (" + command + " - " + ext + ")"
|
||||
print("expected: " + sha1_extract + " found: " + sha1_extract_2)
|
||||
print(d + " - SHA1 mismatch (" + command + " - " + ext + ")")
|
||||
failure = True
|
||||
|
||||
currentDirectory = os.path.dirname(os.path.realpath(__file__))
|
||||
@ -176,7 +180,7 @@ for root, dirs, files in os.walk(inputPath):
|
||||
elif command == "copy":
|
||||
inFile += ".chd"
|
||||
else:
|
||||
print "unsupported mode '%s'" % command
|
||||
print("unsupported mode '%s'" % command)
|
||||
continue
|
||||
if os.path.exists(inFile):
|
||||
cmd = [chdmanBin, command, "-f", "-i", inFile, "-o", tempFile] + params
|
||||
@ -185,27 +189,27 @@ for root, dirs, files in os.walk(inputPath):
|
||||
|
||||
exitcode, stdout, stderr = runProcess(cmd)
|
||||
if not exitcode == 0:
|
||||
print d + " - command failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - command failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
|
||||
# verify
|
||||
exitcode, stdout, stderr = runProcess([chdmanBin, "verify", "-i", tempFile])
|
||||
if not exitcode == 0:
|
||||
print d + " - verify failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - verify failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
|
||||
# compare info
|
||||
# TODO: store expected output of reference file as well and compare
|
||||
exitcode, info1, stderr = runProcess([chdmanBin, "info", "-v", "-i", tempFile])
|
||||
if not exitcode == 0:
|
||||
print d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
exitcode, info2, stderr = runProcess([chdmanBin, "info", "-v", "-i", outFile])
|
||||
if not exitcode == 0:
|
||||
print d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")"
|
||||
print(d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")")
|
||||
failure = True
|
||||
if not compareInfo(info1, info2):
|
||||
print d + " - info output differs"
|
||||
print(d + " - info output differs")
|
||||
failure = True
|
||||
|
||||
# extract and compare
|
||||
@ -222,9 +226,9 @@ for root, dirs, files in os.walk(inputPath):
|
||||
sha1_out = sha1sum(outFile)
|
||||
sha1_temp = sha1sum(tempFile)
|
||||
if not sha1_out == sha1_temp:
|
||||
print "expected: " + sha1_out + " found: " + sha1_temp
|
||||
print d + " - SHA1 mismatch (output file)"
|
||||
print("expected: " + sha1_out + " found: " + sha1_temp)
|
||||
print(d + " - SHA1 mismatch (output file)")
|
||||
failure = True
|
||||
|
||||
if not failure:
|
||||
print "All tests finished successfully"
|
||||
print("All tests finished successfully")
|
||||
|
Loading…
Reference in New Issue
Block a user