Changeset 3436 for pkpgcounter/trunk/tests/gstests.py
- Timestamp:
- 10/06/08 00:22:07 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/tests/gstests.py
r564 r3436 1 1 #! /usr/bin/env python 2 # -*- coding: UTF-8 -*-2 # -*- coding: utf-8 -*- 3 3 # 4 4 # pkpgcounter : a generic Page Description Language parser … … 9 9 # the Free Software Foundation, either version 3 of the License, or 10 10 # (at your option) any later version. 11 # 11 # 12 12 # This program is distributed in the hope that it will be useful, 13 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 # GNU General Public License for more details. 16 # 16 # 17 17 # You should have received a copy of the GNU General Public License 18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. … … 43 43 self.md5sum = self.computeChecksum() 44 44 self.mastersize = None 45 46 def __del__(self) : 45 46 def __del__(self) : 47 47 """Remove temporary file, if any.""" 48 48 if self.tmp is not None : 49 49 self.tmp.close() 50 51 def computeChecksum(self) : 50 51 def computeChecksum(self) : 52 52 """Computes an MD5 checksum for the input file's content.""" 53 53 checksum = md5.new() … … 60 60 infile = sys.stdin 61 61 istemp = True 62 else : 62 else : 63 63 infile = open(self.inputfile, "rb") 64 64 65 65 while True : 66 66 data = infile.read(MEGABYTE) 67 67 if not data : 68 68 break 69 if istemp : 69 if istemp : 70 70 self.tmp.write(data) 71 71 checksum.update(data) 72 73 if istemp : 74 self.tmp.flush() 72 73 if istemp : 74 self.tmp.flush() 75 75 else : 76 76 infile.close() 77 78 return checksum.hexdigest() 79 77 78 return checksum.hexdigest() 79 80 80 def getAvailableDevices(self) : 81 81 """Returns a list of available GhostScript devices. 82 82 83 83 The list is returned without any x11, bbox, nor ijs related device. 84 84 """ … … 93 93 and (not dev == "/nullpage") \ 94 94 and (not dev == "/bbox") ] 95 devices.sort() 95 devices.sort() 96 96 return devices 97 97 return [] 98 98 99 99 def getAvailableIJSPrintClasses(self) : 100 100 """Returns a list of available IJS Print Classes. 101 101 102 102 Currently the list is a static one and doesn't contain all the available print classes. 103 103 """ 104 return [ "DJ3600", "DJ3320", "DJ9xx", "DJGenericVIP", "LJColor", 104 return [ "DJ3600", "DJ3320", "DJ9xx", "DJGenericVIP", "LJColor", 105 105 "DJ850", "DJ890", "DJ9xxVIP", "DJ8xx", "DJ540", "DJ660", 106 106 "DJ6xx", "DJ350", "DJ6xxPhoto", "DJ630", "DJ8x5", "DJ4100", … … 108 108 "Postscript", "LJJetReady", "LJMono", "LJFastRaster", 109 109 "LJZjsMono", ] 110 110 111 111 def batchGeneration(self, infilename, devices, root, command) : 112 112 """Loops over a set of devices calling a particular command.""" … … 121 121 if os.path.exists(outfilename) and os.stat(outfilename).st_size : 122 122 sys.stdout.write("Skipping %(outfilename)s : already exists.\n" % locals()) 123 else : 123 else : 124 124 sys.stdout.write("Generating %(outfilename)s " % locals()) 125 125 sys.stdout.flush() 126 126 os.system(cmd) 127 127 sys.stdout.write("\n") 128 128 129 129 if not os.path.exists(outfilename) : 130 130 sys.stderr.write("ERROR : During the generation of %(outfilename)s\n" % locals()) 131 elif not os.stat(outfilename).st_size : 131 elif not os.stat(outfilename).st_size : 132 132 sys.stderr.write("ERROR : Unsupported driver, impossible to generate %(outfilename)s\n" % locals()) 133 133 os.remove(outfilename) 134 else : 134 else : 135 135 self.results[outfilename] = { "command" : cmd, 136 136 "device" : "%s" % (devprefix + device), … … 138 138 "details" : None, 139 139 } 140 140 141 141 def genTestSuite(self) : 142 142 """Generate the testsuite.""" 143 143 root = "testsuite.%s" % self.md5sum 144 self.batchGeneration(self.inputfile, self.getAvailableDevices(), 145 root, 144 self.batchGeneration(self.inputfile, self.getAvailableDevices(), 145 root, 146 146 'gs -dQUIET -dBATCH -dNOPAUSE -dPARANOIDSAFER -sOutputFile="%(outfilename)s" -sDEVICE="%(device)s" "%(infilename)s"') 147 148 self.batchGeneration(self.inputfile, self.getAvailableIJSPrintClasses(), 149 "%(root)s.hpijs" % locals(), 147 148 self.batchGeneration(self.inputfile, self.getAvailableIJSPrintClasses(), 149 "%(root)s.hpijs" % locals(), 150 150 'gs -dBATCH -dQUIET -dPARANOIDSAFER -dNOPAUSE -sDEVICE=ijs -sIjsServer=hpijs -dIjsUseOutputFD -sDeviceManufacturer="HEWLETT-PACKARD" -sDeviceModel="%(device)s" -sOutputFile="%(outfilename)s" "%(infilename)s"') 151 152 def runPipe(self, cmd) : 151 152 def runPipe(self, cmd) : 153 153 """Runs a command in a pipe, returns the command's output as a string.""" 154 154 answerfd = os.popen(cmd, "r") 155 155 try : 156 156 return answerfd.read().strip() 157 finally : 157 finally : 158 158 answerfd.close() 159 160 def computeSize(self, filename) : 159 160 def computeSize(self, filename) : 161 161 """Computes the size in pages of a file in the testsuite.""" 162 162 answer = self.runPipe('pkpgcounter "%(filename)s" 2>/dev/null' % locals()) 163 163 try : 164 164 return int(answer) 165 except (ValueError, TypeError) : 165 except (ValueError, TypeError) : 166 166 return 0 167 167 168 168 def runTests(self) : 169 169 """Launches the page counting tests against the testsuite.""" … … 172 172 if not mastersize : 173 173 raise RuntimeError, "Unable to compute the size of the testsuite's master file %(masterfilename)s" % locals() 174 else : 174 else : 175 175 sys.stdout.write("Master file's contains %(mastersize)i pages.\n" % locals()) 176 176 testsuite = glob.glob("testsuite.*") … … 181 181 if len(parts) > 3 : 182 182 devname = ".".join(parts[2:]) 183 else : 183 else : 184 184 devname = parts[-1] 185 result = self.results.setdefault(testfname, { "command" : "See above", 186 "device" : devname, 187 "result" : None, 185 result = self.results.setdefault(testfname, { "command" : "See above", 186 "device" : devname, 187 "result" : None, 188 188 "details" : None }) 189 189 sys.stdout.write("Testing %(testfname)s ... " % locals()) … … 194 194 result["result"] = "UNSUPPORTED" 195 195 result["details"] = "Unsupported file format" 196 else : 196 else : 197 197 result["result"] = "FAILED" 198 198 result["details"] = "Found %(size)i pages instead of %(mastersize)i\n" % locals() 199 else : 199 else : 200 200 result["result"] = "SUPPORTED" 201 201 result["details"] = None 202 sys.stdout.write("%s\n" % result["result"]) 202 sys.stdout.write("%s\n" % result["result"]) 203 203 self.supportedpct = 100.0 * len([True for r in self.results.values() if r["result"] == "SUPPORTED"]) / nbtests 204 204 self.failedpct = 100.0 * len([True for r in self.results.values() if r["result"] == "FAILED"]) / nbtests 205 205 self.unsupportedpct = 100.0 * len([True for r in self.results.values() if r["result"] == "UNSUPPORTED"]) / nbtests 206 206 207 207 def genHTMLReport(self, filename) : 208 208 """Generates an HTML report.""" … … 232 232 for key in keys : 233 233 value = self.results[key] 234 linecount += 1 235 if not (linecount % 2) : 234 linecount += 1 235 if not (linecount % 2) : 236 236 linecolor = "#DEDEDE" 237 else : 237 else : 238 238 linecolor = "#FFFFFF" 239 out.write('<tr bgcolor="%s">\n' % linecolor) 239 out.write('<tr bgcolor="%s">\n' % linecolor) 240 240 if value["result"] == "SUPPORTED" : 241 241 color = "#00FF00" 242 elif value["result"] == "UNSUPPORTED" : 242 elif value["result"] == "UNSUPPORTED" : 243 243 color = "#FF0000" 244 else : 244 else : 245 245 color = "orange" 246 246 out.write('<td bgcolor="%s"><strong>%s</strong></td>\n' % (color, value["device"])) … … 250 250 out.write("</table></body></html>\n") 251 251 out.close() 252 253 def main() : 252 253 def main() : 254 254 """Main function.""" 255 255 try : … … 259 259 sys.stderr.write("usage : %s [inputfile.ps]\n" % sys.argv[0]) 260 260 sys.exit(-1) 261 else : 261 else : 262 262 testsuite = TestSuite(sys.argv[1]) 263 263 testsuite.genTestSuite() 264 264 testsuite.runTests() 265 265 testsuite.genHTMLReport("%s.html" % testsuite.md5sum) 266 except KeyboardInterrupt : 266 except KeyboardInterrupt : 267 267 sys.stderr.write("Interrupted at user's request !\n") 268 268 269 269 if __name__ == "__main__" : 270 270 sys.exit(main()) 271 271