[Piglit] [PATCH 2/4] gen_const_builtin_equal_tests.py: Wrap main in a function

Dylan Baker baker.dylan.c at gmail.com
Mon May 19 14:43:53 PDT 2014


This creates main() function and puts things in it. This is good python
style.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 generated_tests/gen_const_builtin_equal_tests.py | 54 +++++++++++++-----------
 1 file changed, 29 insertions(+), 25 deletions(-)

diff --git a/generated_tests/gen_const_builtin_equal_tests.py b/generated_tests/gen_const_builtin_equal_tests.py
index 583f90e..4519184 100644
--- a/generated_tests/gen_const_builtin_equal_tests.py
+++ b/generated_tests/gen_const_builtin_equal_tests.py
@@ -96,38 +96,42 @@ test_vectors = [
         ]
     ]
 
-try:
-    os.makedirs('spec/glsl-1.20/execution/built-in-functions')
-except OSError:
-    pass
 
+def main():
+    """ Main function """
+    try:
+        os.makedirs('spec/glsl-1.20/execution/built-in-functions')
+    except OSError:
+        pass
 
-test_id = 2
-for x in test_vectors:
-    name = "spec/glsl-1.20/execution/built-in-functions/glsl-const-builtin-equal-%02d.shader_test" % test_id
-    test_id = test_id + 1
+    test_id = 2
+    for x in test_vectors:
+        name = "spec/glsl-1.20/execution/built-in-functions/glsl-const-builtin-equal-%02d.shader_test" % test_id
+        test_id = test_id + 1
 
-    print(name)
+        print(name)
 
-    with open(name, 'w+') as f:
-        f.write(TEMPLATE.render_unicode(
-            func='equal', input=x[0:2], expected=x[2]))
+        with open(name, 'w+') as f:
+            f.write(TEMPLATE.render_unicode(
+                func='equal', input=x[0:2], expected=x[2]))
 
 
-test_id = 2
-for x in test_vectors:
-    name = "spec/glsl-1.20/execution/built-in-functions/glsl-const-builtin-notEqual-%02d.shader_test" % test_id
-    test_id = test_id + 1
+    test_id = 2
+    for x in test_vectors:
+        name = "spec/glsl-1.20/execution/built-in-functions/glsl-const-builtin-notEqual-%02d.shader_test" % test_id
+        test_id = test_id + 1
 
-    # When generating the notEqual tests, each of the values in the expected
-    # result vector need to be inverted
+        # When generating the notEqual tests, each of the values in the
+        # expected result vector need to be inverted
+        expected = re.sub("true", "FALSE", x[2])
+        expected = re.sub("false", "TRUE", expected)
+        expected = expected.lower()
 
-    expected = re.sub("true", "FALSE", x[2])
-    expected = re.sub("false", "TRUE", expected)
-    expected = expected.lower()
+        print(name)
 
-    print(name)
+        with open(name, 'w+') as f:
+            f.write(TEMPLATE.render_unicode(
+                func='notEqual', input=x[0:2], expected=expected))
 
-    with open(name, 'w+') as f:
-        f.write(TEMPLATE.render_unicode(
-            func='notEqual', input=x[0:2], expected=expected))
+if __name__ == "__main__":
+    main()
-- 
2.0.0.rc2



More information about the Piglit mailing list