regtest/TestRun.py | 2 +- regtest/backends/__init__.py | 34 ++++++++++++++++++++++++++++++++-- regtest/commands/run-tests.py | 4 ++++ 3 files changed, 37 insertions(+), 3 deletions(-)
New commits: commit 52c1e9c5109299255d13b5b1e7d3eedaab512084 Author: Carlos Garcia Campos <[email protected]> Date: Tue Nov 1 14:13:10 2011 +0100 regtest: Add --update-refs command line option to run-tests command It allows to update the references of failing tests. diff --git a/regtest/TestRun.py b/regtest/TestRun.py index f03840b..80a4d33 100644 --- a/regtest/TestRun.py +++ b/regtest/TestRun.py @@ -66,7 +66,7 @@ class TestRun: self._stderr.append("%s (%s)" % (doc_path, backend.get_name())) 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): + if backend.compare_checksums(refs_path, test_path, not self.config.keep_results, self.config.create_diffs, self.config.update_refs): # FIXME: remove dir if it's empty? print("PASS") self._n_passed += 1 diff --git a/regtest/backends/__init__.py b/regtest/backends/__init__.py index 2e90759..98d5a07 100644 --- a/regtest/backends/__init__.py +++ b/regtest/backends/__init__.py @@ -18,6 +18,8 @@ from hashlib import md5 import os +import shutil +import errno from Config import Config __all__ = [ 'register_backend', @@ -61,12 +63,13 @@ class Backend: md5_file.close() - def compare_checksums(self, refs_path, out_path, remove_results = True, create_diffs = True): + def compare_checksums(self, refs_path, out_path, remove_results = True, create_diffs = True, update_refs = False): retval = True md5_path = os.path.join(refs_path, self._name) md5_file = open(md5_path + '.md5', 'r') tests = os.listdir(out_path) + result_md5 = [] for line in md5_file.readlines(): md5sum, ref_path = line.strip('\n').split(' ', 1) @@ -81,8 +84,13 @@ class Backend: result_path = os.path.join(out_path, basename) f = open(result_path, 'rb') - matched = md5sum == md5(f.read()).hexdigest() + result_md5sum = md5(f.read()).hexdigest() + matched = md5sum == result_md5sum f.close() + + if update_refs: + result_md5.append("%s %s\n" % (result_md5sum, ref_path)) + if matched: if remove_results: os.remove(result_path) @@ -97,9 +105,31 @@ class Backend: except NotImplementedError: # Diff not supported by backend pass + + if update_refs: + if os.path.exists(ref_path): + print("Updating image reference %s" % (ref_path)) + shutil.copyfile(result_path, ref_path) + retval = False md5_file.close() + if update_refs and not retval: + print("Updating md5 reference %s" % (md5_path)) + f = open(md5_path + '.md5.tmp', 'wb') + f.writelines(result_md5) + f.close() + os.rename(md5_path + '.md5.tmp', md5_path + '.md5') + + for ref in ('.crashed', '.failed', '.stderr'): + src = os.path.join(out_path, self._name + ref) + dest = os.path.join(refs_path, self._name + ref) + try: + shutil.copyfile(src, dest) + except IOError as e: + if e.errno != errno.ENOENT: + raise + return retval def has_md5(self, test_path): diff --git a/regtest/commands/run-tests.py b/regtest/commands/run-tests.py index c1a8b6f..d05d815 100644 --- a/regtest/commands/run-tests.py +++ b/regtest/commands/run-tests.py @@ -44,12 +44,16 @@ class RunTests(Command): parser.add_argument('--create-diffs', action = 'store_true', dest = 'create_diffs', default = False, help = 'Create diff files for failed tests') + parser.add_argument('--update-refs', + action = 'store_true', dest = 'update_refs', default = False, + help = 'Update references for failed tests') parser.add_argument('tests') def run(self, options): config = Config() config.keep_results = options['keep_results'] config.create_diffs = options['create_diffs'] + config.update_refs = options['update_refs'] t = Timer() doc = options['tests'] _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
