OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2015 The PDFium Authors. All rights reserved. | 2 # Copyright 2015 The PDFium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import subprocess | |
8 import sys | 7 import sys |
9 | 8 |
| 9 import common |
| 10 |
10 class PNGDiffer(): | 11 class PNGDiffer(): |
11 ACTUAL_TEMPLATE = '.pdf.%d.png' | 12 ACTUAL_TEMPLATE = '.pdf.%d.png' |
12 EXPECTED_TEMPLATE = '_expected' + ACTUAL_TEMPLATE | 13 EXPECTED_TEMPLATE = '_expected' + ACTUAL_TEMPLATE |
13 PLATFORM_EXPECTED_TEMPLATE = '_expected_%s' + ACTUAL_TEMPLATE | 14 PLATFORM_EXPECTED_TEMPLATE = '_expected_%s' + ACTUAL_TEMPLATE |
14 | 15 |
15 def __init__(self, finder): | 16 def __init__(self, finder): |
16 self.pdfium_diff_path = finder.ExecutablePath('pdfium_diff') | 17 self.pdfium_diff_path = finder.ExecutablePath('pdfium_diff') |
17 self.os_name = finder.os_name | 18 self.os_name = finder.os_name |
18 | 19 |
19 def GetActualFiles(self, input_filename, source_dir, working_dir): | 20 def GetActualFiles(self, input_filename, source_dir, working_dir): |
(...skipping 10 matching lines...) Expand all Loading... |
30 platform_expected_path = ( | 31 platform_expected_path = ( |
31 platform_expected_path_template % (self.os_name, i)) | 32 platform_expected_path_template % (self.os_name, i)) |
32 if os.path.exists(platform_expected_path): | 33 if os.path.exists(platform_expected_path): |
33 expected_path = platform_expected_path | 34 expected_path = platform_expected_path |
34 elif not os.path.exists(expected_path): | 35 elif not os.path.exists(expected_path): |
35 break | 36 break |
36 actual_paths.append(actual_path) | 37 actual_paths.append(actual_path) |
37 i += 1 | 38 i += 1 |
38 return actual_paths | 39 return actual_paths |
39 | 40 |
40 def HasDifferences(self, input_filename, source_dir, working_dir): | 41 def HasDifferences(self, input_filename, source_dir, working_dir, |
| 42 redirect_output=False): |
41 template_paths = self._GetTemplatePaths( | 43 template_paths = self._GetTemplatePaths( |
42 input_filename, source_dir, working_dir) | 44 input_filename, source_dir, working_dir) |
43 actual_path_template = template_paths[0]; | 45 actual_path_template = template_paths[0]; |
44 expected_path_template = template_paths[1] | 46 expected_path_template = template_paths[1] |
45 platform_expected_path_template = template_paths[2] | 47 platform_expected_path_template = template_paths[2] |
46 i = 0 | 48 i = 0 |
47 try: | 49 while True: |
48 while True: | 50 actual_path = actual_path_template % i |
49 actual_path = actual_path_template % i | 51 expected_path = expected_path_template % i |
50 expected_path = expected_path_template % i | 52 platform_expected_path = ( |
51 platform_expected_path = ( | 53 platform_expected_path_template % (self.os_name, i)) |
52 platform_expected_path_template % (self.os_name, i)) | 54 if os.path.exists(platform_expected_path): |
53 if os.path.exists(platform_expected_path): | 55 expected_path = platform_expected_path |
54 expected_path = platform_expected_path | 56 elif not os.path.exists(expected_path): |
55 elif not os.path.exists(expected_path): | 57 if i == 0: |
56 if i == 0: | 58 print "WARNING: no expected results files for " + input_filename |
57 print "WARNING: no expected results files for " + input_filename | 59 break |
58 break | 60 print "Checking " + actual_path |
59 print "Checking " + actual_path | 61 sys.stdout.flush() |
60 sys.stdout.flush() | 62 error = common.RunCommand( |
61 subprocess.check_call( | 63 [self.pdfium_diff_path, expected_path, actual_path], redirect_output) |
62 [self.pdfium_diff_path, expected_path, actual_path]) | 64 if error: |
63 i += 1 | 65 print "FAILURE: " + input_filename + "; " + str(error) |
64 except subprocess.CalledProcessError as e: | 66 return True |
65 print "FAILURE: " + input_filename + "; " + str(e) | 67 i += 1 |
66 return True | |
67 return False | 68 return False |
68 | 69 |
69 def _GetTemplatePaths(self, input_filename, source_dir, working_dir): | 70 def _GetTemplatePaths(self, input_filename, source_dir, working_dir): |
70 input_root, _ = os.path.splitext(input_filename) | 71 input_root, _ = os.path.splitext(input_filename) |
71 actual_path = os.path.join(working_dir, input_root + self.ACTUAL_TEMPLATE) | 72 actual_path = os.path.join(working_dir, input_root + self.ACTUAL_TEMPLATE) |
72 expected_path = os.path.join( | 73 expected_path = os.path.join( |
73 source_dir, input_root + self.EXPECTED_TEMPLATE) | 74 source_dir, input_root + self.EXPECTED_TEMPLATE) |
74 platform_expected_path = os.path.join( | 75 platform_expected_path = os.path.join( |
75 source_dir, input_root + self.PLATFORM_EXPECTED_TEMPLATE) | 76 source_dir, input_root + self.PLATFORM_EXPECTED_TEMPLATE) |
76 return (actual_path, expected_path, platform_expected_path) | 77 return (actual_path, expected_path, platform_expected_path) |
OLD | NEW |