[Piglit] [Patch v2 3/9] framework/glsl_parser_test.py: Split more out of the constructor

Dylan Baker baker.dylan.c at gmail.com
Fri Jul 11 08:14:16 PDT 2014


This splits the creation of the command to be passed to super() into a
private method. This change results in more readable code.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/glsl_parser_test.py | 59 ++++++++++++++++++++++++++-----------------
 1 file changed, 36 insertions(+), 23 deletions(-)

diff --git a/framework/glsl_parser_test.py b/framework/glsl_parser_test.py
index e6489f6..21b3f83 100644
--- a/framework/glsl_parser_test.py
+++ b/framework/glsl_parser_test.py
@@ -88,29 +88,42 @@ class GLSLParserTest(PiglitTest):
         with open(filepath, 'r') as testfile:
             text_io = self.__parser(testfile, filepath)
 
-            config = ConfigParser.SafeConfigParser(
-                defaults={'require_extensions': '', 'check_link': 'false'})
-
-            # Verify that the config was valid
-            text = text_io.getvalue()
-            text_io.close()
-            config.readfp(StringIO(text))
-
-            for opt in ['expect_result', 'glsl_version']:
-                if not config.has_option('config', opt):
-                    raise GLSLParserException("Missing required section {} "
-                                              "from config".format(opt))
-
-            # Create the command and pass it into a PiglitTest()
-            command = [path.join(TEST_BIN_DIR, 'glslparsertest'),
-                       filepath,
-                       config.get('config', 'expect_result'),
-                       config.get('config', 'glsl_version')]
-            if config.get('config', 'check_link').lower() == 'true':
-                command.append('--check-link')
-            command.extend(config.get('config', 'require_extensions').split())
-
-            super(GLSLParserTest, self).__init__(command, run_concurrent=True)
+        command = self.__get_command(text_io, filepath)
+        super(GLSLParserTest, self).__init__(command, run_concurrent=True)
+
+    def __get_command(self, text_io, filepath):
+        """ Create the command argument to pass to super()
+
+        This private helper creates a configparser object, then reads in the
+        provided config (from self.__parser), and tests for required options
+        that must be provided. If it does not find them it raises an exception.
+        It then crafts a command which is returned, and ultimately passed to
+        super()
+
+        """
+        config = ConfigParser.SafeConfigParser(
+            defaults={'require_extensions': '', 'check_link': 'false'})
+
+        # Verify that the config was valid
+        text = text_io.getvalue()
+        text_io.close()
+        config.readfp(StringIO(text))
+
+        for opt in ['expect_result', 'glsl_version']:
+            if not config.has_option('config', opt):
+                raise GLSLParserException("Missing required section {} "
+                                          "from config".format(opt))
+
+        # Create the command and pass it into a PiglitTest()
+        command = [path.join(TEST_BIN_DIR, 'glslparsertest'),
+                   filepath,
+                   config.get('config', 'expect_result'),
+                   config.get('config', 'glsl_version')]
+        if config.get('config', 'check_link').lower() == 'true':
+            command.append('--check-link')
+        command.extend(config.get('config', 'require_extensions').split())
+
+        return command
 
     def __parser(self, testfile, filepath):
         """ Private helper that parses the config file
-- 
2.0.0



More information about the Piglit mailing list