diff options
author | Henrique Nakashima <hnakashima@chromium.org> | 2017-10-25 17:31:13 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-25 21:42:45 +0000 |
commit | 06673ede2dda783187fb05f9a97d0bec2f34dd32 (patch) | |
tree | 93be59d46c54aff5a5df6b7046f2d9cddf1cf9c5 /testing/tools/pngdiffer.py | |
parent | 5614d119e91264c428396f9eb84afea866011fca (diff) | |
download | pdfium-06673ede2dda783187fb05f9a97d0bec2f34dd32.tar.xz |
Add --regenerate_expected option to test_runner.py.chromium/3250
After a change in rendering, corpus and pixel test expected pngs
need to be regenerated manually. This option reduces the toil by
automating renaming and moving the new expected files over the old
ones.
Change-Id: I9d490369ccf946d4d4567e440b7b5252469eec46
Reviewed-on: https://pdfium-review.googlesource.com/16451
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Diffstat (limited to 'testing/tools/pngdiffer.py')
-rwxr-xr-x | testing/tools/pngdiffer.py | 92 |
1 files changed, 63 insertions, 29 deletions
diff --git a/testing/tools/pngdiffer.py b/testing/tools/pngdiffer.py index a1533b8329..95acb198a6 100755 --- a/testing/tools/pngdiffer.py +++ b/testing/tools/pngdiffer.py @@ -4,32 +4,26 @@ # found in the LICENSE file. import os +import shutil import sys import common class PNGDiffer(): - ACTUAL_TEMPLATE = '.pdf.%d.png' - EXPECTED_TEMPLATE = '_expected' + ACTUAL_TEMPLATE - PLATFORM_EXPECTED_TEMPLATE = '_expected_%s' + ACTUAL_TEMPLATE - def __init__(self, finder): self.pdfium_diff_path = finder.ExecutablePath('pdfium_diff') self.os_name = finder.os_name def GetActualFiles(self, input_filename, source_dir, working_dir): actual_paths = [] - template_paths = self._GetTemplatePaths( - input_filename, source_dir, working_dir) - actual_path_template = template_paths[0]; - expected_path_template = template_paths[1] - platform_expected_path_template = template_paths[2] + path_templates = PathTemplates(input_filename, source_dir, working_dir) + i = 0 while True: - actual_path = actual_path_template % i - expected_path = expected_path_template % i - platform_expected_path = ( - platform_expected_path_template % (self.os_name, i)) + actual_path = path_templates.GetActualPath(i) + expected_path = path_templates.GetExpectedPath(i) + platform_expected_path = path_templates.GetPlatformExpectedPath( + self.os_name, i) if os.path.exists(platform_expected_path): expected_path = platform_expected_path elif not os.path.exists(expected_path): @@ -39,19 +33,16 @@ class PNGDiffer(): return actual_paths def HasDifferences(self, input_filename, source_dir, working_dir): - template_paths = self._GetTemplatePaths( - input_filename, source_dir, working_dir) - actual_path_template = template_paths[0]; - expected_path_template = template_paths[1] - platform_expected_path_template = template_paths[2] + path_templates = PathTemplates(input_filename, source_dir, working_dir) + i = 0 while True: - actual_path = actual_path_template % i - expected_path = expected_path_template % i + actual_path = path_templates.GetActualPath(i) + expected_path = path_templates.GetExpectedPath(i) # PDFium tests should be platform independent. Platform based results are # used to capture platform dependent implementations. - platform_expected_path = ( - platform_expected_path_template % (self.os_name, i)) + platform_expected_path = path_templates.GetPlatformExpectedPath( + self.os_name, i) if (not os.path.exists(expected_path) and not os.path.exists(platform_expected_path)): if i == 0: @@ -75,11 +66,54 @@ class PNGDiffer(): i += 1 return False - def _GetTemplatePaths(self, input_filename, source_dir, working_dir): + def Regenerate(self, input_filename, source_dir, working_dir): + path_templates = PathTemplates(input_filename, source_dir, working_dir) + + page = 0 + while True: + # 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) + if not os.path.isfile(actual_path): + break + + platform_expected_path = path_templates.GetPlatformExpectedPath( + self.os_name, page) + + # If there is a platform expected png, we will overwrite it. Otherwise, + # overwrite the generic png. + if os.path.exists(platform_expected_path): + expected_path = platform_expected_path + else: + expected_path = path_templates.GetExpectedPath(page) + + if os.path.exists(expected_path): + shutil.copyfile(actual_path, expected_path) + + page += 1 + + +ACTUAL_TEMPLATE = '.pdf.%d.png' +EXPECTED_TEMPLATE = '_expected' + ACTUAL_TEMPLATE +PLATFORM_EXPECTED_TEMPLATE = '_expected_%s' + ACTUAL_TEMPLATE + + +class PathTemplates(object): + + def __init__(self, input_filename, source_dir, working_dir): input_root, _ = os.path.splitext(input_filename) - actual_path = os.path.join(working_dir, input_root + self.ACTUAL_TEMPLATE) - expected_path = os.path.join( - source_dir, input_root + self.EXPECTED_TEMPLATE) - platform_expected_path = os.path.join( - source_dir, input_root + self.PLATFORM_EXPECTED_TEMPLATE) - return (actual_path, expected_path, platform_expected_path) + self.actual_path_template = os.path.join(working_dir, + input_root + ACTUAL_TEMPLATE) + self.expected_path = os.path.join( + source_dir, input_root + EXPECTED_TEMPLATE) + self.platform_expected_path = os.path.join( + source_dir, input_root + PLATFORM_EXPECTED_TEMPLATE) + + def GetActualPath(self, page): + return self.actual_path_template % page + + def GetExpectedPath(self, page): + return self.expected_path % page + + def GetPlatformExpectedPath(self, platform, page): + return self.platform_expected_path % (platform, page) |