Previous 199869 Revisions Next

r36295 Friday 6th March, 2015 at 21:08:58 UTC by Mike Naberezny
chdtest.py: Python 3 compat. (nw)
[src/regtests/chdman]chdtest.py

trunk/src/regtests/chdman/chdtest.py
r244806r244807
77def runProcess(cmd):
88   process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
99   (stdout, stderr) = process.communicate()
10   if not isinstance(stdout, str): # python 3
11      stdout = stdout.decode('latin-1')
12   if not isinstance(stderr, str): # python 3
13      stderr = stderr.decode('latin-1')
1014   return process.returncode, stdout, stderr
1115   
1216def compareInfo(info1, info2):
r244806r244807
2327         continue
2428      if not lines1[i] == lines2[i]:
2529         mismatch = True
26         print lines1[i] + " - " + lines2[i]
30         print(lines1[i] + " - " + lines2[i])
2731   
2832   return mismatch == False
2933
r244806r244807
5458   
5559   exitcode, stdout, stderr = runProcess([chdmanBin, "extractcd", "-f", "-i", outFile, "-o", extractFile])
5660   if not exitcode == 0:
57      print d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")"
61      print(d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")")
5862      failure = True
5963   
6064   sha1_extract = sha1sum(extractFile)
r244806r244807
6973   
7074   exitcode, stdout, stderr = runProcess([chdmanBin, "extractcd", "-f", "-i", tempFile, "-o", extractFile])
7175   if not exitcode == 0:
72      print d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")"
76      print(d + " - extractcd (" + type + ") failed with " + str(exitcode) + " (" + stderr + ")")
7377      failure = True
7478     
7579   sha1_extract_2 = sha1sum(extractFile)
7680   sha1_extract_bin_2 = sha1sum(extractFileBin)
7781     
7882   if not sha1_extract == sha1_extract_2:
79      print "expected: " + sha1_extract + " found: " + sha1_extract_2
80      print d + " - SHA1 mismatch (extractcd - " + type + " - toc)"
83      print("expected: " + sha1_extract + " found: " + sha1_extract_2)
84      print(d + " - SHA1 mismatch (extractcd - " + type + " - toc)")
8185      failure = True
8286
8387   if not sha1_extract_bin == sha1_extract_bin_2:
84      print "expected: " + sha1_extract_bin + " found: " + sha1_extract_bin_2
85      print d + " - SHA1 mismatch (extractcd - " + type + " - bin)"
88      print("expected: " + sha1_extract_bin + " found: " + sha1_extract_bin_2)
89      print(d + " - SHA1 mismatch (extractcd - " + type + " - bin)")
8690      failure = True
8791     
8892def extractAndCompare(command, ext):
r244806r244807
9599   
96100   exitcode, stdout, stderr = runProcess([chdmanBin, command, "-f", "-i", outFile, "-o", extractFile])
97101   if not exitcode == 0:
98      print d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")"
102      print(d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")")
99103      failure = True
100104   
101105   sha1_extract = sha1sum(extractFile)
r244806r244807
108112   
109113   exitcode, stdout, stderr = runProcess([chdmanBin, command, "-f", "-i", tempFile, "-o", extractFile])
110114   if not exitcode == 0:
111      print d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")"
115      print(d + " - " + command + " (" + ext + ") failed with " + str(exitcode) + " (" + stderr + ")")
112116      failure = True
113117     
114118   sha1_extract_2 = sha1sum(extractFile)
115119     
116120   if not sha1_extract == sha1_extract_2:
117      print "expected: " + sha1_extract + " found: " + sha1_extract_2
118      print d + " - SHA1 mismatch (" + command + " - " + ext + ")"
121      print("expected: " + sha1_extract + " found: " + sha1_extract_2)
122      print(d + " - SHA1 mismatch (" + command + " - " + ext + ")")
119123      failure = True
120124
121125currentDirectory = os.path.dirname(os.path.realpath(__file__))
r244806r244807
176180      elif command == "copy":
177181         inFile += ".chd"
178182      else:
179         print "unsupported mode '%s'" % command
183         print("unsupported mode '%s'" % command)
180184         continue
181185      if os.path.exists(inFile):
182186         cmd = [chdmanBin, command, "-f", "-i", inFile, "-o", tempFile] + params
r244806r244807
185189
186190      exitcode, stdout, stderr = runProcess(cmd)
187191      if not exitcode == 0:
188         print d + " - command failed with " + str(exitcode) + " (" + stderr + ")"
192         print(d + " - command failed with " + str(exitcode) + " (" + stderr + ")")
189193         failure = True
190194     
191195      # verify
192196      exitcode, stdout, stderr = runProcess([chdmanBin, "verify", "-i", tempFile])
193197      if not exitcode == 0:
194         print d + " - verify failed with " + str(exitcode) + " (" + stderr + ")"
198         print(d + " - verify failed with " + str(exitcode) + " (" + stderr + ")")
195199         failure = True
196200         
197201      # compare info
198202      # TODO: store expected output of reference file as well and compare
199203      exitcode, info1, stderr = runProcess([chdmanBin, "info", "-v", "-i", tempFile])
200204      if not exitcode == 0:
201         print d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")"
205         print(d + " - info (temp) failed with " + str(exitcode) + " (" + stderr + ")")
202206         failure = True
203207      exitcode, info2, stderr = runProcess([chdmanBin, "info", "-v", "-i", outFile])
204208      if not exitcode == 0:
205         print d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")"
209         print(d + " - info (output) failed with " + str(exitcode) + " (" + stderr + ")")
206210         failure = True
207211      if not compareInfo(info1, info2):
208         print d + " - info output differs"
212         print(d + " - info output differs")
209213         failure = True
210214         
211215      # extract and compare
r244806r244807
222226      sha1_out = sha1sum(outFile)
223227      sha1_temp = sha1sum(tempFile)
224228      if not sha1_out == sha1_temp:
225         print "expected: " + sha1_out + " found: " + sha1_temp
226         print d + " - SHA1 mismatch (output file)"
229         print("expected: " + sha1_out + " found: " + sha1_temp)
230         print(d + " - SHA1 mismatch (output file)")
227231         failure = True
228232
229233if not failure:
230   print "All tests finished successfully"
No newline at end of file
234   print("All tests finished successfully")


Previous 199869 Revisions Next


© 1997-2024 The MAME Team