[Piglit] [PATCH 6/9] framework/exectest.py: Do unicode conversion in get_command_result()

Dylan Baker baker.dylan.c at gmail.com
Wed Apr 9 18:27:24 PDT 2014


This patch moves the unicode conversion out of run and into
get_command_result. Since this is meant to fix the python2
unicode/bytestring madness it makes more sense to do this earlier rather
than later.

Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
---
 framework/exectest.py | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/framework/exectest.py b/framework/exectest.py
index 6752ee3..b83536a 100644
--- a/framework/exectest.py
+++ b/framework/exectest.py
@@ -170,23 +170,6 @@ class Test(object):
                 else:
                     break
 
-            # proc.communicate() returns 8-bit strings, but we need
-            # unicode strings.  In Python 2.x, this is because we
-            # will eventually be serializing the strings as JSON,
-            # and the JSON library expects unicode.  In Python 3.x,
-            # this is because all string operations require
-            # unicode.  So translate the strings into unicode,
-            # assuming they are using UTF-8 encoding.
-            #
-            # If the subprocess output wasn't properly UTF-8
-            # encoded, we don't want to raise an exception, so
-            # translate the strings using 'replace' mode, which
-            # replaces erroneous charcters with the Unicode
-            # "replacement character" (a white question mark inside
-            # a black diamond).
-            out = out.decode('utf-8', 'replace')
-            err = err.decode('utf-8', 'replace')
-
             results = TestResult()
 
             if skip:
@@ -276,6 +259,24 @@ class Test(object):
                 returncode = None
             else:
                 raise e
+
+        # proc.communicate() returns 8-bit strings, but we need
+        # unicode strings.  In Python 2.x, this is because we
+        # will eventually be serializing the strings as JSON,
+        # and the JSON library expects unicode.  In Python 3.x,
+        # this is because all string operations require
+        # unicode.  So translate the strings into unicode,
+        # assuming they are using UTF-8 encoding.
+        #
+        # If the subprocess output wasn't properly UTF-8
+        # encoded, we don't want to raise an exception, so
+        # translate the strings using 'replace' mode, which
+        # replaces erroneous charcters with the Unicode
+        # "replacement character" (a white question mark inside
+        # a black diamond).
+        out = out.decode('utf-8', 'replace')
+        err = err.decode('utf-8', 'replace')
+
         return out, err, returncode
 
 
-- 
1.9.1



More information about the Piglit mailing list