python/test: Move the image comparison logic to the base test class.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 30 Mar 2009 16:51:55 +0000 (17:51 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 30 Mar 2009 16:51:55 +0000 (17:51 +0100)
src/gallium/state_trackers/python/tests/base.py
src/gallium/state_trackers/python/tests/texture.py

index 8477aa5fc9b5a6c6d64319991ba040602cdf1458..2df2af0cdf2ae4c5dc7235228b40b63eec9e1111 100644 (file)
@@ -33,6 +33,8 @@ Loosely inspired on Python's unittest module.
 """
 
 
+import sys
+
 from gallium import *
 
 
@@ -115,6 +117,23 @@ class Test:
         self._run(result)
         result.summary()
 
+    def assert_rgba(self, surface, x, y, w, h, expected_rgba, pixel_tol=4.0/256, surface_tol=0.85):
+        total = h*w
+        different = surface.compare_tile_rgba(x, y, w, h, expected_rgba, tol=pixel_tol)
+        if different:
+            sys.stderr.write("%u out of %u pixels differ\n" % (different, total))
+
+        if float(total - different)/float(total) < surface_tol:
+            if 0:
+                rgba = FloatArray(h*w*4)
+                surface.get_tile_rgba(x, y, w, h, rgba)
+                show_image(w, h, Result=rgba, Expected=expected_rgba)
+                save_image(w, h, rgba, "result.png")
+                save_image(w, h, expected_rgba, "expected.png")
+            #sys.exit(0)
+            
+            raise TestFailure
+
 
 class TestCase(Test):
     
@@ -190,4 +209,4 @@ class TestResult:
         print "%u tests, %u passed, %u skipped, %u failed" % (self.tests, self.passed, self.skipped, self.failed)
         for description in self.failed_descriptions:
             print "  %s" % description
\ No newline at end of file
index bd95f734fe79180b2fdd62baac1f0ae250408131..58b7e1c12460253db153ed8024b426e712cc9e22 100644 (file)
@@ -27,7 +27,6 @@
 ##########################################################################
 
 
-import sys
 from gallium import *
 from base import *
 
@@ -291,22 +290,7 @@ class TextureTest(TestCase):
     
         cbuf = cbuf_tex.get_surface()
         
-        total = h*w
-        different = cbuf.compare_tile_rgba(x, y, w, h, expected_rgba, tol=4.0/256)
-        if different:
-            sys.stderr.write("%u out of %u pixels differ\n" % (different, total))
-
-        if float(total - different)/float(total) < 0.85:
-        
-            if 0:
-                rgba = FloatArray(h*w*4)
-                cbuf.get_tile_rgba(x, y, w, h, rgba)
-                show_image(w, h, Result=rgba, Expected=expected_rgba)
-                save_image(w, h, rgba, "result.png")
-                save_image(w, h, expected_rgba, "expected.png")
-            #sys.exit(0)
-            
-            raise TestFailure
+        self.assert_rgba(cbuf, x, y, w, h, expected_rgba, 4.0/256, 0.85)
 
         del ctx