[gs-cvs] rev 7707 - trunk/gs/toolbin/tests

giles at ghostscript.com giles at ghostscript.com
Fri Feb 16 11:08:04 PST 2007


Author: giles
Date: 2007-02-16 11:08:03 -0800 (Fri, 16 Feb 2007)
New Revision: 7707

Modified:
   trunk/gs/toolbin/tests/gscheck_pdfwrite.py
   trunk/gs/toolbin/tests/gscheck_raster.py
   trunk/gs/toolbin/tests/rasterdb.py
Log:
Improve the encapsulation of the raster db by adding exists() and 
mtime() methods instead of checking the stored files directly in
the caller.


Modified: trunk/gs/toolbin/tests/gscheck_pdfwrite.py
===================================================================
--- trunk/gs/toolbin/tests/gscheck_pdfwrite.py	2007-02-16 15:27:49 UTC (rev 7706)
+++ trunk/gs/toolbin/tests/gscheck_pdfwrite.py	2007-02-16 19:08:03 UTC (rev 7707)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-#    Copyright (C) 2001-2004 Artifex Software Inc.
+#    Copyright (C) 2001-2007 Artifex Software Inc.
 # 
 # This file is part of AFPL Ghostscript.
 # 
@@ -25,36 +25,36 @@
 # compares Ghostscript against a baseline made from file->pdf->raster->md5sum.
 # this test tries to detect Ghostscript changes that affect the pdfwrite driver.
 
-import os, stat
+import os
 import calendar, string, time
 import gstestutils
 import gsconf, gstestgs, gsparamsets, gssum, gsutil
+import rasterdb
 
-
 class GSPDFWriteCompareTestCase(gstestgs.GhostscriptTestCase):
+    def makefilename(self):
+        return "%s.pdf.%s.%d.%d" % (self.file[string.rindex(self.file, '/') + 1:], self.device, self.dpi, self.band)
+	
     def shortDescription(self):
-        file = "%s.pdf.%s.%d.%d" % (self.file[string.rindex(self.file, '/') + 1:], self.device, self.dpi, self.band)
-	rasterfilename = gsconf.rasterdbdir + file + ".gz"
-	if not os.access(rasterfilename, os.F_OK):
+        file = self.makefilename()
+	if not rasterdb.exists(file):
 		os.system(gsconf.codedir + "update_pdfbaseline '%s'" %
                           (os.path.basename(self.file),))
+		self.skip = 1
         try:
-            ct = time.localtime(os.stat(rasterfilename)[stat.ST_MTIME])
+            ct = time.localtime(rasterdb.mtime(file))
             baseline_date = "%s %d, %4d %02d:%02d" % (
                 calendar.month_abbr[ct[1]], ct[2], ct[0], ct[3], ct[4])
         except:
-            if self.band: banded = "banded"
-            else: banded = "noband"
             self.skip = 1
 
+        if self.band: banded = "banded"
+        else: banded = "noband"
+        if hasattr(self, "skip") and self.skip:
       	    return "Skipping pdfwrite %s (%s/%ddpi/%s) [no previous raster data found]" % (os.path.basename(self.file), self.device, self.dpi, banded)
-
-	if self.band:
-	    return "Checking pdfwrite of %s (%s/%ddpi/banded) against baseline set on %s" % (os.path.basename(self.file), self.device, self.dpi, baseline_date)
         else:
-	    return "Checking pdfwrite of %s (%s/%ddpi/noband) against baseline set on %s" % (os.path.basename(self.file), self.device, self.dpi, baseline_date)
+	    return "Checking pdfwrite of %s (%s/%ddpi/%s) against baseline set on %s" % (os.path.basename(self.file), self.device, self.dpi, banded, baseline_date)
 
-	
     def runTest(self):
         if hasattr(self, "skip") and self.skip:
 	    self.assert_(True)

Modified: trunk/gs/toolbin/tests/gscheck_raster.py
===================================================================
--- trunk/gs/toolbin/tests/gscheck_raster.py	2007-02-16 15:27:49 UTC (rev 7706)
+++ trunk/gs/toolbin/tests/gscheck_raster.py	2007-02-16 19:08:03 UTC (rev 7707)
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 
-#    Copyright (C) 2001-2004 Artifex Software Inc.
+#    Copyright (C) 2001-2007 Artifex Software Inc.
 # 
 # This software is provided AS-IS with no warranty, either express or
 # implied.
@@ -25,40 +25,42 @@
 #
 
 
-import os, stat
+import os
 import string, calendar, time
 import gstestutils
 import gssum, gsconf, gstestgs, gsparamsets, gsutil
+import rasterdb
 
 class GSCompareTestCase(gstestgs.GhostscriptTestCase):
+    def makefilename(self):
+        file = "%s.%s.%d.%d" % (self.file[string.rindex(self.file, '/') + 1:], self.device, self.dpi, self.band)
+	return file
+
     def shortDescription(self):
-        file = "%s.%s.%d.%d" % (self.file[string.rindex(self.file, '/') + 1:], self.device, self.dpi, self.band)
-	rasterfilename = gsconf.rasterdbdir + file + ".gz"
-	if not os.access(rasterfilename, os.F_OK):
+	file = self.makefilename()
+	if not rasterdb.exists(file):
 		os.system(gsconf.codedir + "update_baseline '%s'" %
                           (os.path.basename(self.file),))
+		self.skip = 1
 	try:
-		ct = time.localtime(os.stat(rasterfilename)[stat.ST_MTIME])
+		ct = time.localtime(rasterdb.mtime(file))
 		baseline_date = "%s %d, %4d %02d:%02d" % ( calendar.month_abbr[ct[1]], ct[2], ct[0], ct[3], ct[4] )
 	except:
-		if self.band:
-			banded = "banded"
-		else:
-			banded = "noband"
 		self.skip = 1
+
+	if self.band: banded = "banded"
+	else: banded = "noband"
+	if hasattr(self, "skip") and self.skip:
 		return "Skipping %s (%s/%ddpi/%s) [no previous raster data found]" % (os.path.basename(self.file), self.device, self.dpi, banded)
+	else:
+		return "Checking %s (%s/%ddpi/%s) against baseline set on %s" % (os.path.basename(self.file), self.device, self.dpi, banded, baseline_date)
 
-	if self.band:
-	    return "Checking %s (%s/%ddpi/banded) against baseline set on %s" % (os.path.basename(self.file), self.device, self.dpi, baseline_date)
-        else:
-	    return "Checking %s (%s/%ddpi/noband) against baseline set on %s" % (os.path.basename(self.file), self.device, self.dpi, baseline_date)
-
     def runTest(self):
         if hasattr(self, "skip") and self.skip == 1:
 	    self.assert_(True)
 	    return
 
-	file = "%s.%s.%d.%d" % (self.file[string.rindex(self.file, '/') + 1:], self.device, self.dpi, self.band)
+	file = self.makefilename()
 
 	gs = gstestgs.Ghostscript()
 	gs.command = self.gs

Modified: trunk/gs/toolbin/tests/rasterdb.py
===================================================================
--- trunk/gs/toolbin/tests/rasterdb.py	2007-02-16 15:27:49 UTC (rev 7706)
+++ trunk/gs/toolbin/tests/rasterdb.py	2007-02-16 19:08:03 UTC (rev 7707)
@@ -1,4 +1,4 @@
-#    Copyright (C) 2001 Artifex Software Inc.
+#    Copyright (C) 2001-2007 Artifex Software Inc.
 #
 # This software is provided AS-IS with no warranty, either express or
 # implied.
@@ -24,16 +24,20 @@
 import gsconf
 
 def exists(file, dbdir=gsconf.rasterdbdir):
-    x = 0
+    x = False
     try:
         mode = os.stat(dbdir + file + '.gz')[ST_MODE]
         if S_ISREG(mode):
-            x = 1
+            x = True
     except:
         pass
     
     return x
 
+def mtime(file, dbdir=gsconf.rasterdbdir):
+    'return the modification time of the entry'
+    return os.stat(dbdir + file + '.gz')[ST_MTIME]
+
 def get_file(file, dbdir=gsconf.rasterdbdir, output=None):
     if exists(file, dbdir):
         if output:



More information about the gs-cvs mailing list