[Piglit] [RFC 07/25] gen_tes_input_tests.py: use texwrap.dedent

Dylan Baker baker.dylan.c at gmail.com
Wed Oct 7 14:17:08 PDT 2015


This increases the readability of the file by allowing the long test
string to be indented.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 generated_tests/gen_tes_input_tests.py | 189 +++++++++++++++++----------------
 1 file changed, 95 insertions(+), 94 deletions(-)

diff --git a/generated_tests/gen_tes_input_tests.py b/generated_tests/gen_tes_input_tests.py
index d716ca0..a0a0fdb 100644
--- a/generated_tests/gen_tes_input_tests.py
+++ b/generated_tests/gen_tes_input_tests.py
@@ -44,6 +44,7 @@ from __future__ import print_function, absolute_import, division
 import os
 import sys
 import random
+import textwrap
 
 from six.moves import range
 
@@ -208,100 +209,100 @@ class Test(object):
 
     def generate(self):
         """Generates and writes the test to disc."""
-        test = \
-"""# Test generated by:
-# {generator_command}
-# Test tessellation control shader inputs
-[require]
-GLSL >= 1.50
-GL_ARB_tessellation_shader
-
-[vertex shader]
-void main()
-{{
-        gl_Position = vec4(0);
-}}
-
-[tessellation control shader]
-#extension GL_ARB_tessellation_shader : require
-layout(vertices = 3) out;
-
-uniform struct S0 {{
-        {self.var_type_full} v;
-}} reference[12];
-
-#if {self.use_block}
-{self.interface_prefix}out {self.interface_name} {{
-        {self.var_type_full} {self.var_name};
-}} {self.interface_tcs_instance}{self.interface_postfix};
-#else
-{self.interface_prefix}out {self.var_type_full} {self.var_name};
-#endif
-
-void main()
-{{
-        const int vertices_in = 3;
-        {self.interface_tcs_instance}{self.tcs_var_ref} = reference[{self.tcs_reference_index}].v;
-        gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
-        gl_TessLevelInner = float[2](1.0, 1.0);
-}}
-
-[tessellation evaluation shader]
-#extension GL_ARB_tessellation_shader : require
-layout(quads) in;
-
-uniform struct S0 {{
-        {self.var_type_full} v;
-}} reference[12];
-
-#if {self.use_block}
-{self.interface_prefix}in {self.interface_name} {{
-        {self.var_type_full} {self.var_name};
-}} {self.interface_tes_instance}{self.interface_postfix};
-#else
-{self.interface_prefix}in {self.var_type_full} {self.var_name};
-#endif
-
-out vec4 vert_color;
-
-void main()
-{{
-        const int vertices_in = 3;
-        const vec4 red = vec4(1, 0, 0, 1);
-        const vec4 green = vec4(0, 1, 0, 1);
-        vert_color = green;
-        for (int i = 0; i < vertices_in; ++i)
-                if ({self.interface_tes_instance}{self.tes_var_ref} != reference[{self.tes_reference_index}].v)
-                        vert_color = red;
-        vec2[3] position = vec2[3](
-                vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 1.0),
-                vec2(float(gl_PrimitiveID / 2) - 0.0, float(gl_PrimitiveID % 2) - 1.0),
-                vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 0.0)
-        );
-        gl_Position = vec4(position[0]
-                    + (position[1] - position[0]) * gl_TessCoord[0]
-                    + (position[2] - position[0]) * gl_TessCoord[1], 0.0, 1.0);
-}}
-
-[fragment shader]
-
-in vec4 vert_color;
-
-out vec4 frag_color;
-
-void main()
-{{
-        frag_color = vert_color;
-}}
-
-[test]
-{self.uniform_string}
-draw arrays GL_PATCHES 0 12
-relative probe rgb (0.25, 0.25) (0.0, 1.0, 0.0)
-relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
-relative probe rgb (0.25, 0.75) (0.0, 1.0, 0.0)
-relative probe rgb (0.75, 0.75) (0.0, 1.0, 0.0)
-"""
+        test = textwrap.dedent("""\
+            # Test generated by:
+            # {generator_command}
+            # Test tessellation control shader inputs
+            [require]
+            GLSL >= 1.50
+            GL_ARB_tessellation_shader
+
+            [vertex shader]
+            void main()
+            {{
+                    gl_Position = vec4(0);
+            }}
+
+            [tessellation control shader]
+            #extension GL_ARB_tessellation_shader : require
+            layout(vertices = 3) out;
+
+            uniform struct S0 {{
+                    {self.var_type_full} v;
+            }} reference[12];
+
+            #if {self.use_block}
+            {self.interface_prefix}out {self.interface_name} {{
+                    {self.var_type_full} {self.var_name};
+            }} {self.interface_tcs_instance}{self.interface_postfix};
+            #else
+            {self.interface_prefix}out {self.var_type_full} {self.var_name};
+            #endif
+
+            void main()
+            {{
+                    const int vertices_in = 3;
+                    {self.interface_tcs_instance}{self.tcs_var_ref} = reference[{self.tcs_reference_index}].v;
+                    gl_TessLevelOuter = float[4](1.0, 1.0, 1.0, 1.0);
+                    gl_TessLevelInner = float[2](1.0, 1.0);
+            }}
+
+            [tessellation evaluation shader]
+            #extension GL_ARB_tessellation_shader : require
+            layout(quads) in;
+
+            uniform struct S0 {{
+                    {self.var_type_full} v;
+            }} reference[12];
+
+            #if {self.use_block}
+            {self.interface_prefix}in {self.interface_name} {{
+                    {self.var_type_full} {self.var_name};
+            }} {self.interface_tes_instance}{self.interface_postfix};
+            #else
+            {self.interface_prefix}in {self.var_type_full} {self.var_name};
+            #endif
+
+            out vec4 vert_color;
+
+            void main()
+            {{
+                    const int vertices_in = 3;
+                    const vec4 red = vec4(1, 0, 0, 1);
+                    const vec4 green = vec4(0, 1, 0, 1);
+                    vert_color = green;
+                    for (int i = 0; i < vertices_in; ++i)
+                            if ({self.interface_tes_instance}{self.tes_var_ref} != reference[{self.tes_reference_index}].v)
+                                    vert_color = red;
+                    vec2[3] position = vec2[3](
+                            vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 1.0),
+                            vec2(float(gl_PrimitiveID / 2) - 0.0, float(gl_PrimitiveID % 2) - 1.0),
+                            vec2(float(gl_PrimitiveID / 2) - 1.0, float(gl_PrimitiveID % 2) - 0.0)
+                    );
+                    gl_Position = vec4(position[0]
+                                + (position[1] - position[0]) * gl_TessCoord[0]
+                                + (position[2] - position[0]) * gl_TessCoord[1], 0.0, 1.0);
+            }}
+
+            [fragment shader]
+
+            in vec4 vert_color;
+
+            out vec4 frag_color;
+
+            void main()
+            {{
+                    frag_color = vert_color;
+            }}
+
+            [test]
+            {self.uniform_string}
+            draw arrays GL_PATCHES 0 12
+            relative probe rgb (0.25, 0.25) (0.0, 1.0, 0.0)
+            relative probe rgb (0.75, 0.25) (0.0, 1.0, 0.0)
+            relative probe rgb (0.25, 0.75) (0.0, 1.0, 0.0)
+            relative probe rgb (0.75, 0.75) (0.0, 1.0, 0.0)
+            """)
 
         test = test.format(self=self, generator_command=" ".join(sys.argv))
 
-- 
2.6.0



More information about the Piglit mailing list