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

Side by Side Diff: testing/tools/gold.py

Issue 2649313005: Add flag to ignore images by their MD5 digest (Closed)
Patch Set: Removed debug statement Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | testing/tools/test_runner.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The PDFium Authors. All rights reserved. 1 # Copyright 2015 The PDFium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 5
6 import json 6 import json
7 import os 7 import os
8 import shlex 8 import shlex
9 import shutil 9 import shutil
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 # "md5" : "0b955f387740c66eb23bf0e253c80d64", 44 # "md5" : "0b955f387740c66eb23bf0e253c80d64",
45 # "options" : { 45 # "options" : {
46 # "ext" : "png", 46 # "ext" : "png",
47 # "gamma_correct" : "no" 47 # "gamma_correct" : "no"
48 # } 48 # }
49 # } 49 # }
50 # ], 50 # ],
51 # } 51 # }
52 # 52 #
53 class GoldResults(object): 53 class GoldResults(object):
54 def __init__(self, source_type, outputDir, propertiesStr, keyStr): 54 def __init__(self, source_type, outputDir, propertiesStr, keyStr,
55 ignore_hashes_file):
55 """ 56 """
56 source_type is the source_type (=corpus) field used for all results. 57 source_type is the source_type (=corpus) field used for all results.
57 output_dir is the directory where the resulting images are copied and 58 output_dir is the directory where the resulting images are copied and
58 the dm.json file is written. 59 the dm.json file is written.
59 propertiesStr is a string with space separated key/value pairs that 60 propertiesStr is a string with space separated key/value pairs that
60 is used to set the top level fields in the output JSON file. 61 is used to set the top level fields in the output JSON file.
61 keyStr is a string with space separated key/value pairs that 62 keyStr is a string with space separated key/value pairs that
62 is used to set the 'key' field in the output JSON file. 63 is used to set the 'key' field in the output JSON file.
64 ignore_hashes_file is a file that contains a list of image hashes
65 that should be ignored.
63 """ 66 """
64 self._source_type = source_type 67 self._source_type = source_type
65 self._properties = self._parseKeyValuePairs(propertiesStr) 68 self._properties = self._parseKeyValuePairs(propertiesStr)
66 self._properties["key"] = self._parseKeyValuePairs(keyStr) 69 self._properties["key"] = self._parseKeyValuePairs(keyStr)
67 self._results = [] 70 self._results = []
68 self._outputDir = outputDir 71 self._outputDir = outputDir
69 72
70 # make sure the output directory exists. 73 # make sure the output directory exists.
71 if not os.path.exists(outputDir): 74 if not os.path.exists(outputDir):
72 os.makedirs(outputDir) 75 os.makedirs(outputDir)
73 76
77 self._ignore_hashes = set()
78 if ignore_hashes_file:
79 with open(ignore_hashes_file, 'r') as ig_file:
80 hashes=[x.strip() for x in ig_file.readlines() if x.strip()]
81 self._ignore_hashes = set(hashes)
82
74 def AddTestResult(self, testName, md5Hash, outputImagePath): 83 def AddTestResult(self, testName, md5Hash, outputImagePath):
75 # Copy the image to <output_dir>/<md5Hash>.<image_extension> 84 # If the hash is in the list of hashes to ignore then we don'try
85 # make a copy, but add it to the result.
76 imgExt = os.path.splitext(outputImagePath)[1].lstrip(".") 86 imgExt = os.path.splitext(outputImagePath)[1].lstrip(".")
77 if not imgExt: 87 if md5Hash not in self._ignore_hashes:
78 raise ValueError("File %s does not have an extension" % outputImagePath) 88 # Copy the image to <output_dir>/<md5Hash>.<image_extension>
79 newFilePath = os.path.join(self._outputDir, md5Hash + '.' + imgExt) 89 if not imgExt:
80 shutil.copy2(outputImagePath, newFilePath) 90 raise ValueError("File %s does not have an extension" % outputImagePath)
91 newFilePath = os.path.join(self._outputDir, md5Hash + '.' + imgExt)
92 shutil.copy2(outputImagePath, newFilePath)
81 93
82 # Add an entry to the list of test results 94 # Add an entry to the list of test results
83 self._results.append({ 95 self._results.append({
84 "key": { 96 "key": {
85 "name": testName, 97 "name": testName,
86 "source_type": self._source_type, 98 "source_type": self._source_type,
87 }, 99 },
88 "md5": md5Hash, 100 "md5": md5Hash,
89 "options": { 101 "options": {
90 "ext": imgExt, 102 "ext": imgExt,
(...skipping 25 matching lines...) Expand all
116 os.makedirs(testDir) 128 os.makedirs(testDir)
117 open(os.path.join(testDir, "image1.png"), 'wb').close() 129 open(os.path.join(testDir, "image1.png"), 'wb').close()
118 open(os.path.join(testDir, "image2.png"), 'wb').close() 130 open(os.path.join(testDir, "image2.png"), 'wb').close()
119 open(os.path.join(testDir, "image3.png"), 'wb').close() 131 open(os.path.join(testDir, "image3.png"), 'wb').close()
120 132
121 # Create an instance and add results. 133 # Create an instance and add results.
122 propStr = """build_number 2 "builder name" Builder-Name gitHash a4a338179013b0 29d6dd55e737b5bd648a9fb68c""" 134 propStr = """build_number 2 "builder name" Builder-Name gitHash a4a338179013b0 29d6dd55e737b5bd648a9fb68c"""
123 135
124 keyStr = "arch arm64 compiler Clang configuration Debug" 136 keyStr = "arch arm64 compiler Clang configuration Debug"
125 137
126 gr = GoldResults("pdfium", testDir, propStr, keyStr) 138 hash_file = os.path.join(testDir, "ignore_hashes.txt")
139 with open(hash_file, 'wb') as f:
140 f.write("\n".join(["hash-1","hash-4"]) + "\n")
141
142 gr = GoldResults("pdfium", testDir, propStr, keyStr, hash_file)
127 gr.AddTestResult("test-1", "hash-1", os.path.join(testDir, "image1.png")) 143 gr.AddTestResult("test-1", "hash-1", os.path.join(testDir, "image1.png"))
128 gr.AddTestResult("test-2", "hash-2", os.path.join(testDir, "image2.png")) 144 gr.AddTestResult("test-2", "hash-2", os.path.join(testDir, "image2.png"))
129 gr.AddTestResult("test-3", "hash-3", os.path.join(testDir, "image3.png")) 145 gr.AddTestResult("test-3", "hash-3", os.path.join(testDir, "image3.png"))
130 gr.WriteResults() 146 gr.WriteResults()
OLDNEW
« no previous file with comments | « no previous file | testing/tools/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698