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

index 2df2af0cdf2ae4c5dc7235228b40b63eec9e1111..10964d99568a0a4d958fff724e14b9aae652cc2e 100644 (file)
@@ -137,14 +137,54 @@ class Test:
 
 class TestCase(Test):
     
+    tags = ()
+
     def __init__(self, dev, **kargs):
         Test.__init__(self)
         self.dev = dev
         self.__dict__.update(kargs)
 
     def description(self):
-        raise NotImplementedError
-        
+        descriptions = []
+        for tag in self.tags:
+            try:
+                method = getattr(self, '_describe_' + tag)
+            except AttributeError:
+                description = str(getattr(self, tag, None))
+            else:
+                description = method()
+            if description is not None:
+                descriptions.append(tag + '=' + description)
+        return ' '.join(descriptions)
+
+    def _describe_target(self):
+        return {
+            PIPE_TEXTURE_1D: "1d", 
+            PIPE_TEXTURE_2D: "2d", 
+            PIPE_TEXTURE_3D: "3d", 
+            PIPE_TEXTURE_CUBE: "cube",
+        }[self.target]
+
+    def _describe_format(self):
+        name = formats[self.format]
+        if name.startswith('PIPE_FORMAT_'):
+            name  = name[12:]
+        name = name.lower()
+        return name
+
+    def _describe_face(self):
+        if self.target == PIPE_TEXTURE_CUBE:
+            return {
+                PIPE_TEX_FACE_POS_X: "+x",
+                PIPE_TEX_FACE_NEG_X: "-x",
+                PIPE_TEX_FACE_POS_Y: "+y",
+                PIPE_TEX_FACE_NEG_Y: "-y", 
+                PIPE_TEX_FACE_POS_Z: "+z", 
+                PIPE_TEX_FACE_NEG_Z: "-z",
+            }[self.face]
+        else:
+            return None
+
     def test(self):
         raise NotImplementedError
     
index 58b7e1c12460253db153ed8024b426e712cc9e22..fcb347f9a17f089a40e4329ddc767e56bfe6f59a 100644 (file)
@@ -100,31 +100,18 @@ def is_pot(n):
                 
 class TextureTest(TestCase):
     
-    def description(self):
-        target = {
-            PIPE_TEXTURE_1D: "1d", 
-            PIPE_TEXTURE_2D: "2d", 
-            PIPE_TEXTURE_3D: "3d", 
-            PIPE_TEXTURE_CUBE: "cube",
-        }[self.target]
-        format = formats[self.format]
-        if self.target == PIPE_TEXTURE_CUBE:
-            face = {
-                PIPE_TEX_FACE_POS_X: "+x",
-                PIPE_TEX_FACE_NEG_X: "-x",
-                PIPE_TEX_FACE_POS_Y: "+y",
-                PIPE_TEX_FACE_NEG_Y: "-y", 
-                PIPE_TEX_FACE_POS_Z: "+z", 
-                PIPE_TEX_FACE_NEG_Z: "-z",
-            }[self.face]
-        else:
-            face = ""
-        return "%s %s %ux%ux%u last_level=%u face=%s level=%u zslice=%u" % (
-            target, format, 
-            self.width, self.height, self.depth, self.last_level, 
-            face, self.level, self.zslice, 
-        )
-    
+    tags = (
+        'target',
+        'format',
+        'width',
+        'height',
+        'depth',
+        'last_level',
+        'face',
+        'level',
+        'zslice',
+    )
+
     def test(self):
         dev = self.dev