[poppler] regtest/backends regtest/commands regtest/Config.py regtest/main.py regtest/TestReferences.py regtest/TestRun.py regtest/Timer.py
Albert Astals Cid
aacid at kemper.freedesktop.org
Tue Sep 13 15:54:37 PDT 2011
regtest/Config.py | 4 ++--
regtest/TestReferences.py | 8 ++++----
regtest/TestRun.py | 32 ++++++++++++++++----------------
regtest/Timer.py | 8 ++++----
regtest/backends/__init__.py | 12 ++++++------
regtest/commands/__init__.py | 6 +++---
regtest/commands/create-refs.py | 2 +-
regtest/commands/run-tests.py | 2 +-
regtest/main.py | 2 +-
9 files changed, 38 insertions(+), 38 deletions(-)
New commits:
commit 93ba92db0a3af35f197a4faa5a528af98ea0f624
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Sep 14 00:58:44 2011 +0200
Make it work with Python3
diff --git a/regtest/Config.py b/regtest/Config.py
index 197edce..ff03e3c 100644
--- a/regtest/Config.py
+++ b/regtest/Config.py
@@ -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)
diff --git a/regtest/TestReferences.py b/regtest/TestReferences.py
index 042b0d4..cfd4853 100644
--- a/regtest/TestReferences.py
+++ b/regtest/TestReferences.py
@@ -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)
diff --git a/regtest/TestRun.py b/regtest/TestRun.py
index ba74b1a..f03840b 100644
--- a/regtest/TestRun.py
+++ b/regtest/TestRun.py
@@ -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")
diff --git a/regtest/Timer.py b/regtest/Timer.py
index 102af96..e86f8c5 100644
--- a/regtest/Timer.py
+++ b/regtest/Timer.py
@@ -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()))
diff --git a/regtest/backends/__init__.py b/regtest/backends/__init__.py
index e730eaa..ed728ff 100644
--- a/regtest/backends/__init__.py
+++ b/regtest/backends/__init__.py
@@ -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()
diff --git a/regtest/commands/__init__.py b/regtest/commands/__init__.py
index 93cec6c..86f58fd 100644
--- a/regtest/commands/__init__.py
+++ b/regtest/commands/__init__.py
@@ -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>'")
diff --git a/regtest/commands/create-refs.py b/regtest/commands/create-refs.py
index 081a7e8..b055703 100644
--- a/regtest/commands/create-refs.py
+++ b/regtest/commands/create-refs.py
@@ -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)
diff --git a/regtest/commands/run-tests.py b/regtest/commands/run-tests.py
index 2c564c7..c1a8b6f 100644
--- a/regtest/commands/run-tests.py
+++ b/regtest/commands/run-tests.py
@@ -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)
diff --git a/regtest/main.py b/regtest/main.py
index 4c8a390..a46a64c 100644
--- a/regtest/main.py
+++ b/regtest/main.py
@@ -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)
More information about the poppler
mailing list