summaryrefslogtreecommitdiff
path: root/testing/tools
diff options
context:
space:
mode:
Diffstat (limited to 'testing/tools')
-rwxr-xr-xtesting/tools/pngdiffer.py39
-rw-r--r--testing/tools/test_runner.py18
2 files changed, 31 insertions, 26 deletions
diff --git a/testing/tools/pngdiffer.py b/testing/tools/pngdiffer.py
index a9bc9d6529..f40cc2596f 100755
--- a/testing/tools/pngdiffer.py
+++ b/testing/tools/pngdiffer.py
@@ -3,6 +3,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import itertools
import os
import shutil
import sys
@@ -18,35 +19,37 @@ class PNGDiffer():
actual_paths = []
path_templates = PathTemplates(input_filename, source_dir, working_dir)
- i = 0
- while True:
- actual_path = path_templates.GetActualPath(i)
- expected_path = path_templates.GetExpectedPath(i)
+ for page in itertools.count():
+ actual_path = path_templates.GetActualPath(page)
+ expected_path = path_templates.GetExpectedPath(page)
platform_expected_path = path_templates.GetPlatformExpectedPath(
- self.os_name, i)
+ self.os_name, page)
if os.path.exists(platform_expected_path):
expected_path = platform_expected_path
elif not os.path.exists(expected_path):
break
actual_paths.append(actual_path)
- i += 1
+
return actual_paths
def HasDifferences(self, input_filename, source_dir, working_dir):
path_templates = PathTemplates(input_filename, source_dir, working_dir)
- i = 0
- while True:
- actual_path = path_templates.GetActualPath(i)
- expected_path = path_templates.GetExpectedPath(i)
+ for page in itertools.count():
+ actual_path = path_templates.GetActualPath(page)
+ expected_path = path_templates.GetExpectedPath(page)
# PDFium tests should be platform independent. Platform based results are
# used to capture platform dependent implementations.
platform_expected_path = path_templates.GetPlatformExpectedPath(
- self.os_name, i)
+ self.os_name, page)
if (not os.path.exists(expected_path) and
not os.path.exists(platform_expected_path)):
- if i == 0:
+ if page == 0:
print "WARNING: no expected results files for " + input_filename
+ if os.path.exists(actual_path):
+ print ('FAILURE: Missing expected result for 0-based page %d of %s'
+ % (page, input_filename))
+ return True
break
print "Checking " + actual_path
sys.stdout.flush()
@@ -63,14 +66,13 @@ class PNGDiffer():
if error:
print "FAILURE: " + input_filename + "; " + str(error)
return True
- i += 1
+
return False
def Regenerate(self, input_filename, source_dir, working_dir, platform_only):
path_templates = PathTemplates(input_filename, source_dir, working_dir)
- page = 0
- while True:
+ for page in itertools.count():
# Loop through the generated page images. Stop when there is a page
# missing a png, which means the document ended.
actual_path = path_templates.GetActualPath(page)
@@ -88,12 +90,9 @@ class PNGDiffer():
elif not platform_only:
expected_path = path_templates.GetExpectedPath(page)
else:
- expected_path = None
-
- if expected_path is not None and os.path.exists(expected_path):
- shutil.copyfile(actual_path, expected_path)
+ continue
- page += 1
+ shutil.copyfile(actual_path, expected_path)
ACTUAL_TEMPLATE = '.pdf.%d.png'
diff --git a/testing/tools/test_runner.py b/testing/tools/test_runner.py
index 90202f8e55..5acda86f54 100644
--- a/testing/tools/test_runner.py
+++ b/testing/tools/test_runner.py
@@ -80,21 +80,27 @@ class TestRunner:
if actual_images:
if self.image_differ.HasDifferences(input_filename, source_dir,
self.working_dir):
- if (self.options.regenerate_expected
- and not self.test_suppressor.IsResultSuppressed(input_filename)
- and not self.test_suppressor.IsImageDiffSuppressed(input_filename)):
- platform_only = (self.options.regenerate_expected == 'platform')
- self.image_differ.Regenerate(input_filename, source_dir,
- self.working_dir, platform_only)
+ self.RegenerateIfNeeded_(input_filename, source_dir)
return False, results
else:
if (self.enforce_expected_images
and not self.test_suppressor.IsImageDiffSuppressed(input_filename)):
+ self.RegenerateIfNeeded_(input_filename, source_dir)
print 'FAILURE: %s; Missing expected images' % input_filename
return False, results
return True, results
+ def RegenerateIfNeeded_(self, input_filename, source_dir):
+ if (not self.options.regenerate_expected
+ or self.test_suppressor.IsResultSuppressed(input_filename)
+ or self.test_suppressor.IsImageDiffSuppressed(input_filename)):
+ return
+
+ platform_only = (self.options.regenerate_expected == 'platform')
+ self.image_differ.Regenerate(input_filename, source_dir,
+ self.working_dir, platform_only)
+
def Generate(self, source_dir, input_filename, input_root, pdf_path):
original_path = os.path.join(source_dir, input_filename)
input_path = os.path.join(source_dir, input_root + '.in')