Commit 93ba92db authored by Albert Astals Cid's avatar Albert Astals Cid

Make it work with Python3

parent da1b5437
......@@ -27,6 +27,6 @@ class Config:
if __name__ == '__main__':
c = Config({'foo' : 25})
print c.foo
print(c.foo)
cc = Config()
print cc.foo
print(cc.foo)
......@@ -32,7 +32,7 @@ class TestReferences:
try:
os.makedirs(self._refsdir)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
except:
......@@ -46,7 +46,7 @@ class TestReferences:
refs_path = os.path.join(self._refsdir, filename)
try:
os.makedirs(refs_path)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
except:
......@@ -60,9 +60,9 @@ class TestReferences:
for backend in backends:
if not self.config.force and backend.has_md5(refs_path):
print "Checksum file found, skipping '%s' for %s backend (%d/%d)" % (doc_path, backend.get_name(), n_doc, total_docs)
print("Checksum file found, skipping '%s' for %s backend (%d/%d)" % (doc_path, backend.get_name(), n_doc, total_docs))
continue
print "Creating refs for '%s' using %s backend (%d/%d)" % (doc_path, backend.get_name(), n_doc, total_docs)
print("Creating refs for '%s' using %s backend (%d/%d)" % (doc_path, backend.get_name(), n_doc, total_docs))
if backend.create_refs(doc_path, refs_path):
backend.create_checksums(refs_path, self.config.checksums_only)
......
......@@ -42,7 +42,7 @@ class TestRun:
try:
os.makedirs(self._outdir);
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
except:
......@@ -54,7 +54,7 @@ class TestRun:
ref_is_crashed = backend.is_crashed(refs_path)
ref_is_failed = backend.is_failed(refs_path)
if not ref_has_md5 and not ref_is_crashed and not ref_is_failed:
print "Reference files not found, skipping '%s' for %s backend" % (doc_path, backend.get_name())
print("Reference files not found, skipping '%s' for %s backend" % (doc_path, backend.get_name()))
return
self._n_tests += 1
......@@ -68,40 +68,40 @@ class TestRun:
if ref_has_md5 and test_has_md5:
if backend.compare_checksums(refs_path, test_path, not self.config.keep_results, self.config.create_diffs):
# FIXME: remove dir if it's empty?
print "PASS"
print("PASS")
self._n_passed += 1
else:
print "FAIL"
print("FAIL")
self._failed.append("%s (%s)" % (doc_path, backend.get_name()))
return
elif test_has_md5:
if ref_is_crashed:
print "DOES NOT CRASH"
print("DOES NOT CRASH")
elif ref_is_failed:
print "DOES NOT FAIL"
print("DOES NOT FAIL")
return
test_is_crashed = backend.is_crashed(test_path)
if ref_is_crashed and test_is_crashed:
print "PASS (Expected crash)"
print("PASS (Expected crash)")
self._n_passed += 1
return
test_is_failed = backend.is_failed(test_path)
if ref_is_failed and test_is_failed:
# FIXME: compare status errors
print "PASS (Expected fail with status error %d)" % (test_is_failed)
print("PASS (Expected fail with status error %d)" % (test_is_failed))
self._n_passed += 1
return
if test_is_crashed:
print "CRASH"
print("CRASH")
self._crashed.append("%s (%s)" % (doc_path, backend.get_name()))
return
if test_is_failed:
print "FAIL (status error %d)" % (test_is_failed)
print("FAIL (status error %d)" % (test_is_failed))
self._failed_status_error("%s (%s)" % (doc_path, backend.get_name()))
return
......@@ -113,7 +113,7 @@ class TestRun:
out_path = os.path.join(self._outdir, filename)
try:
os.makedirs(out_path)
except OSError, e:
except OSError as e:
if e.errno != errno.EEXIST:
raise
except:
......@@ -122,7 +122,7 @@ class TestRun:
refs_path = os.path.join(self._refsdir, filename)
if not os.path.isdir(refs_path):
print "Reference dir not found for %s, skipping (%d/%d)" % (doc_path, n_doc, total_docs)
print("Reference dir not found for %s, skipping (%d/%d)" % (doc_path, n_doc, total_docs))
return
if self.config.backends:
......@@ -142,16 +142,16 @@ class TestRun:
def summary(self):
if not self._n_tests:
print "No tests run"
print("No tests run")
return
print "Total %d tests" % (self._n_tests)
print "%d tests passed (%.2f%%)" % (self._n_passed, (self._n_passed * 100.) / self._n_tests)
print("Total %d tests" % (self._n_tests))
print("%d tests passed (%.2f%%)" % (self._n_passed, (self._n_passed * 100.) / self._n_tests))
def report_tests(test_list, test_type):
n_tests = len(test_list)
if not n_tests:
return
print "%d tests %s (%.2f%%): %s" % (n_tests, test_type, (n_tests * 100.) / self._n_tests, ", ".join(test_list))
print("%d tests %s (%.2f%%): %s" % (n_tests, test_type, (n_tests * 100.) / self._n_tests, ", ".join(test_list)))
report_tests(self._failed, "failed")
report_tests(self._crashed, "crashed")
report_tests(self._failed_status_error, "failed to run")
......
......@@ -61,13 +61,13 @@ if __name__ == '__main__':
t = Timer()
sleep(5)
print "Elapsed: %s" % (t.elapsed_str())
print("Elapsed: %s" % (t.elapsed_str()))
sleep(1)
print "Elapsed: %s" % (t.elapsed_str())
print("Elapsed: %s" % (t.elapsed_str()))
t.start()
sleep(2)
t.stop()
print "Elapsed: %s" % (t.elapsed_str())
print("Elapsed: %s" % (t.elapsed_str()))
sleep(2)
print "Elapsed: %s" % (t.elapsed_str())
print("Elapsed: %s" % (t.elapsed_str()))
......@@ -46,7 +46,7 @@ class Backend:
if not entry.startswith(self._name) or entry.endswith('.md5'):
continue
ref_path = os.path.join(refs_path, entry)
f = open(ref_path, 'r')
f = open(ref_path, 'rb')
md5_file.write("%s %s\n" % (md5(f.read()).hexdigest(), ref_path))
f.close()
if delete_refs:
......@@ -66,21 +66,21 @@ class Backend:
basename = os.path.basename(ref_path)
if not basename in tests:
retval = False
print "%s found in md5 ref file but missing in output dir %s" % (basename, out_path)
print("%s found in md5 ref file but missing in output dir %s" % (basename, out_path))
continue
result_path = os.path.join(out_path, basename)
f = open(result_path, 'r')
f = open(result_path, 'rb')
matched = md5sum == md5(f.read()).hexdigest()
f.close()
if matched:
if remove_results:
os.remove(result_path)
else:
print "Differences found in %s" % (basename)
print("Differences found in %s" % (basename))
if create_diffs:
if not os.path.exists(ref_path):
print "Reference file %s not found, skipping diff for %s" % (ref_path, result_path)
print("Reference file %s not found, skipping diff for %s" % (ref_path, result_path))
else:
try:
self._create_diff(ref_path, result_path)
......@@ -115,7 +115,7 @@ class Backend:
def __create_stderr_file(self, stderr, out_path):
if not stderr:
return
stderr_file = open(out_path + '.stderr', 'w')
stderr_file = open(out_path + '.stderr', 'wb')
stderr_file.write(stderr)
stderr_file.close()
......
......@@ -83,11 +83,11 @@ def print_help():
except ImportError:
pass
print "Commands are:"
print("Commands are:")
commands = [(x.name, x.description) for x in _commands.values()]
commands.sort()
for name, description in commands:
print " %-15s %s" % (name, description)
print(" %-15s %s" % (name, description))
print
print "For more information run 'poppler-regtest --help-command <command>'"
print("For more information run 'poppler-regtest --help-command <command>'")
......@@ -60,6 +60,6 @@ class CreateRefs(Command):
refs.create_refs()
else:
refs.create_refs_for_file(os.path.basename(doc))
print "Refs created in %s" % (t.elapsed_str())
print("Refs created in %s" % (t.elapsed_str()))
register_command('create-refs', CreateRefs)
......@@ -64,6 +64,6 @@ class RunTests(Command):
else:
tests.run_test(os.path.basename(doc))
tests.summary()
print "Tests run in %s" % (t.elapsed_str())
print("Tests run in %s" % (t.elapsed_str()))
register_command('run-tests', RunTests)
......@@ -71,7 +71,7 @@ def main(args):
sys.stderr.write("Unknown command: %s\n" % (args[0]))
commands.print_help()
sys.exit(1)
except backends.UnknownBackendError, e:
except backends.UnknownBackendError as e:
sys.stderr.write(str(e) + "\n")
sys.stdout.write("Backends are: %s\n" % (", ".join([backend.get_name() for backend in backends.get_all_backends()])))
sys.exit(1)
......
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