diff options
author | Tom Sepez <tsepez@chromium.org> | 2015-04-03 13:21:53 -0700 |
---|---|---|
committer | Tom Sepez <tsepez@chromium.org> | 2015-04-03 13:21:53 -0700 |
commit | 6ce87f3e283a2cf44cacbcea7f0dc72633682b5b (patch) | |
tree | a32a688b9266078ca7463d21a4d956ae260a3d36 /testing/tools/pngdiffer.py | |
parent | 18d971d1b6f2cd91fc04c38afa5b04b05b538c98 (diff) | |
download | pdfium-6ce87f3e283a2cf44cacbcea7f0dc72633682b5b.tar.xz |
Refactor PDFium python test utilities.
Extract a common portions for determining suppressions and comparing pngs.
R=thestig@chromium.org
Review URL: https://codereview.chromium.org/1057983003
Diffstat (limited to 'testing/tools/pngdiffer.py')
-rwxr-xr-x | testing/tools/pngdiffer.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/testing/tools/pngdiffer.py b/testing/tools/pngdiffer.py new file mode 100755 index 0000000000..dc65b4717f --- /dev/null +++ b/testing/tools/pngdiffer.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python +# Copyright 2015 The PDFium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import os +import subprocess +import sys + +class PNGDiffer(): + ACTUAL_TEMPLATE = '.pdf.%d.png' + EXPECTED_TEMPLATE = '_expected' + ACTUAL_TEMPLATE + + def __init__(self, finder): + self.pdfium_diff_path = finder.ExecutablePath('pdfium_diff') + + def HasDifferences(self, input_filename, source_dir, working_dir): + input_root, _ = os.path.splitext(input_filename) + actual_path_template = os.path.join( + working_dir, input_root + self.ACTUAL_TEMPLATE) + expected_path_template = os.path.join( + source_dir, input_root + self.EXPECTED_TEMPLATE) + i = 0 + try: + while True: + actual_path = actual_path_template % i; + expected_path = expected_path_template % i; + if not os.path.exists(expected_path): + if i == 0: + print "WARNING: no expected results files for " + input_filename + break + print "Checking " + actual_path + sys.stdout.flush() + subprocess.check_call( + [self.pdfium_diff_path, expected_path, actual_path]) + i += 1 + except subprocess.CalledProcessError as e: + print "FAILURE: " + input_filename + "; " + str(e) + return True + return False |