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

Dylan Baker baker.dylan.c at gmail.com
Mon May 19 17:42:04 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 | 55 +++++++++++++-----------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/generated_tests/gen_const_builtin_equal_tests.py b/generated_tests/gen_const_builtin_equal_tests.py
index ddc1b13..7efd31b 100644
--- a/generated_tests/gen_const_builtin_equal_tests.py
+++ b/generated_tests/gen_const_builtin_equal_tests.py
@@ -96,38 +96,41 @@ 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
+        expected = re.sub("true", "FALSE", x[2])
+        expected = re.sub("false", "TRUE", expected)
+        expected = expected.lower()
 
-    # When generating the notEqual tests, each of the values in the expected
-    # result vector need to be inverted
+        print(name)
 
-    expected = re.sub("true", "FALSE", x[2])
-    expected = re.sub("false", "TRUE", expected)
-    expected = expected.lower()
+        with open(name, 'w') as f:
+            f.write(TEMPLATE.render_unicode(
+                func='notEqual', input=x[0:2], expected=expected))
 
-    print(name)
-
-    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