Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1974)

Unified Diff: testing/tools/pngdiffer.py

Issue 1057983003: Refactor PDFium python test utilities. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Line wrap. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | testing/tools/run_corpus_tests.py » ('j') | testing/tools/run_corpus_tests.py » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/tools/pngdiffer.py
diff --git a/testing/tools/pngdiffer.py b/testing/tools/pngdiffer.py
new file mode 100755
index 0000000000000000000000000000000000000000..1891044481c3f0b7f56d913ac92e055f09ddeb7c
--- /dev/null
+++ b/testing/tools/pngdiffer.py
@@ -0,0 +1,94 @@
+#!/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():
+ def __init__(self, os_name, pdfium_diff_path):
+ self.pdfium_diff_path = pdfium_diff_path
+ self.actual_template = '.pdf.%d.png'
Lei Zhang 2015/04/02 23:16:20 this can be a class constant
Tom Sepez 2015/04/03 18:13:14 Done.
+ self.expected_template = '_expected' + self.actual_template
+ # os_name to be used shortly for platform-specifc result files.
+
+ 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
+
+
+# Testing.
Lei Zhang 2015/04/02 23:16:20 Other python projects within the chromium-sphere p
Tom Sepez 2015/04/03 18:13:15 Comment is misleading. This makes a command-line
+def main(argv):
+ if sys.platform.startswith('linux'):
Lei Zhang 2015/04/02 23:16:20 This can go in to common.py since we use it everyw
Tom Sepez 2015/04/03 18:13:14 Done.
+ os_name = 'linux'
+ elif sys.platform.startswith('win'):
+ os_name = 'win'
+ elif sys.platform.startswith('darwin'):
+ os_name = 'mac'
+ else:
+ print 'Confused, can not determine OS, aborting.'
+ return 1
+
+ if len(argv) != 4:
+ print "usage: %s <filename> <source-dir> <working-dir>" % argv[0]
+ return 1
+
+ # Expect |my_dir| to be .../pdfium/testing/tools.
+ my_dir = os.path.dirname(os.path.realpath(__file__))
+ testing_dir = os.path.dirname(my_dir)
+ pdfium_dir = os.path.dirname(testing_dir)
+ if (os.path.basename(my_dir) != 'tools' or
+ os.path.basename(testing_dir) != 'testing'):
+ print 'Confused, can not find pdfium root directory, aborting.'
+ return 1
+
+ # Find path to build directory. This depends on whether this is a
+ # standalone build vs. a build as part of a chromium checkout. For
+ # standalone, we expect a path like .../pdfium/out/Debug, but for
+ # chromium, we expect a path like .../src/out/Debug two levels
+ # higher (to skip over the third_party/pdfium path component under
+ # which chromium sticks pdfium).
+ base_dir = pdfium_dir
+ one_up_dir = os.path.dirname(base_dir)
+ two_up_dir = os.path.dirname(one_up_dir)
+ if (os.path.basename(two_up_dir) == 'src' and
+ os.path.basename(one_up_dir) == 'third_party'):
+ base_dir = two_up_dir
+ build_dir = os.path.join(base_dir, 'out', 'Debug')
+
+ # Compiled binaries are found under the build path.
+ pdfium_diff_path = os.path.join(build_dir, 'pdfium_diff')
+ if sys.platform.startswith('win'):
+ pdfium_diff_path = pdfium_diff_path + '.exe'
+
+ differ = PNGDiffer(os_name, pdfium_diff_path)
+ if differ.HasDifferences(argv[1], argv[2], argv[3]):
+ print "Returned true"
+
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « no previous file | testing/tools/run_corpus_tests.py » ('j') | testing/tools/run_corpus_tests.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698