[Piglit] [PATCH] glsl_parser_test.py: Make exit for bad test configurations pretty

Dylan Baker baker.dylan.c at gmail.com
Sat Aug 23 16:38:19 PDT 2014


Previously an exception would be raised and not caught when a bad
configuration option was set in a glsl_parser_config block. This was
confusing however, because the error is not actually in the python code,
but in the test code.

This patch causes the exception to be caught, and the error message
printed to stderr, and then a clean exit with a returncode of 1 to be
issued. The hope is that it will make it clearer what is wrong and how
to fix it.

This also required changing the unit tests just a little, since they
need to check for a SystemExit exception rather than a
GLSLParserrException.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 framework/glsl_parser_test.py             |  8 +++++++-
 framework/tests/glsl_parser_test_tests.py | 22 ++++++++++++++--------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index 1277c07..dfe2f76 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -21,9 +21,11 @@
 
 """ This module enables the running of GLSL parser tests. """
 
+from __future__ import print_function
 import os
 import os.path as path
 import re
+import sys
 
 from .exectest import PiglitTest
 
@@ -90,7 +92,11 @@ class GLSLParserTest(PiglitTest):
         # Parse the config file and get the config section, then write this
         # section to a StringIO and pass that to ConfigParser
         with open(filepath, 'r') as testfile:
-            config = self.__parser(testfile, filepath)
+            try:
+                config = self.__parser(testfile, filepath)
+            except GLSLParserException as e:
+                print(e.message, file=sys.stderr)
+                sys.exit(1)
 
         command = self.__get_command(config, filepath)
         super(GLSLParserTest, self).__init__(command, run_concurrent=True)
diff --git a/framework/tests/glsl_parser_test_tests.py b/framework/tests/glsl_parser_test_tests.py
index b8af98c..5d3f61e 100644
--- a/framework/tests/glsl_parser_test_tests.py
+++ b/framework/tests/glsl_parser_test_tests.py
@@ -20,12 +20,18 @@
 
 """ Provides tests for the shader_test module """
 
+import sys
 import os
 import nose.tools as nt
 import framework.glsl_parser_test as glsl
 import framework.tests.utils as utils
 from framework.exectest import TEST_BIN_DIR
 
+# Nose does not capture stderr, so all of the error catching tetss will spam
+# the console, however, it does capture stdout, so redirecting stderr to stdout
+# will cause it to be captured in the event that something is wrong.
+sys.stderr = sys.stdout
+
 
 def _check_config(content):
     """ This is the test that actually checks the glsl config section """
@@ -39,7 +45,7 @@ def test_no_config_start():
                '// glsl_version: 1.00\n'
                '// [end config]\n')
     with utils.with_tempfile(content) as tfile:
-        with nt.assert_raises(glsl.GLSLParserException) as exc:
+        with nt.assert_raises(SystemExit) as exc:
             glsl.GLSLParserTest(tfile)
             nt.assert_equal(
                 exc.exception, 'No [config] section found!',
@@ -52,7 +58,7 @@ def test_find_config_start():
                '// glsl_version: 1.00\n'
                '//\n')
     with utils.with_tempfile(content) as tfile:
-        with nt.assert_raises(glsl.GLSLParserException) as exc:
+        with nt.assert_raises(SystemExit) as exc:
             glsl.GLSLParserTest(tfile)
             nt.assert_not_equal(
                 exc.exception, 'No [config] section found!',
@@ -62,7 +68,7 @@ def test_find_config_start():
 def test_no_config_end():
     """ GLSLParserTest requires [end config] """
     with utils.with_tempfile('// [config]\n') as tfile:
-        with nt.assert_raises(glsl.GLSLParserException) as exc:
+        with nt.assert_raises(SystemExit) as exc:
             glsl.GLSLParserTest(tfile)
             nt.assert_equal(
                 exc.exception, 'No [end config] section found!',
@@ -75,7 +81,7 @@ def test_no_expect_result():
                '// glsl_version: 1.00\n'
                '//\n')
     with utils.with_tempfile(content) as tfile:
-        with nt.assert_raises(glsl.GLSLParserException) as exc:
+        with nt.assert_raises(SystemExit) as exc:
             glsl.GLSLParserTest(tfile)
             nt.assert_equal(
                 exc.exception,
@@ -89,7 +95,7 @@ def test_no_glsl_version():
                '// expect_result: pass\n'
                '// [end config]\n')
     with utils.with_tempfile(content) as tfile:
-        with nt.assert_raises(glsl.GLSLParserException) as exc:
+        with nt.assert_raises(SystemExit) as exc:
             glsl.GLSLParserTest(tfile)
             nt.assert_equal(
                 exc.exception,
@@ -205,7 +211,7 @@ def test_bad_section_name():
                '// new_awesome_key: foo\n'
                '// [end config]\n')
 
-    with nt.assert_raises(glsl.GLSLParserException) as e:
+    with nt.assert_raises(SystemExit) as e:
         _, name = _check_config(content)
 
         nt.eq_(e.exception.message,
@@ -230,7 +236,7 @@ def test_good_section_names():
 
 def check_no_duplicates(content, dup):
     """ Ensure that duplicate entries raise an error """
-    with nt.assert_raises(glsl.GLSLParserException) as e:
+    with nt.assert_raises(SystemExit) as e:
         with utils.with_tempfile(content) as tfile:
             glsl.GLSLParserTest(tfile)
 
@@ -259,7 +265,7 @@ def test_duplicate_entries():
 
 def check_bad_character(tfile):
     """ Check for bad characters """
-    with nt.assert_raises(glsl.GLSLParserException) as e:
+    with nt.assert_raises(SystemExit) as e:
         glsl.GLSLParserTest(tfile)
 
         # Obviously this isn't a perfect check, but it should be close enough
-- 
2.0.4



More information about the Piglit mailing list