compiler/glsl/tests: Make tests python3 safe
authorDylan Baker <dylan@pnwbakers.com>
Thu, 16 Aug 2018 21:17:24 +0000 (14:17 -0700)
committerDylan Baker <dylan@pnwbakers.com>
Wed, 22 Aug 2018 15:41:01 +0000 (08:41 -0700)
v2: - explicitly decode the output of subprocesses
    - handle bytes and string types consistently rather than relying on
      python 2's coercion for bytes and ignoring them in python 3
v3: - explicitly set encode as well as decode
    - python 2.7 and 3.x `bytes` instead of defining an alias

Reviewed-by: Mathieu Bridon <bochecha@daitauha.fr>
src/compiler/glsl/tests/lower_jump_cases.py
src/compiler/glsl/tests/optimization_test.py
src/compiler/glsl/tests/sexps.py

index b50ab73479819fdf26f437e799c343503d723033..1977f3a9b4f21b2f5168be643269fdb288786212 100644 (file)
@@ -54,7 +54,7 @@ def make_test_case(f_name, ret_type, body):
                     else:
                         make_declarations(s, already_declared)
     make_declarations(body)
-    return declarations.values() + \
+    return list(declarations.values()) + \
         [['function', f_name, ['signature', ret_type, ['parameters'], body]]]
 
 
index 577d2dfc20f3147f7ff051448605a385dcdd6349..b3147ed08fcf67ce8a6c1175f81e12216ec2f8eb 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 # encoding=utf-8
 # Copyright © 2018 Intel Corporation
 
@@ -71,7 +71,9 @@ def main():
                 stdout=subprocess.PIPE,
                 stderr=subprocess.PIPE,
                 stdin=subprocess.PIPE)
-            out, err = proc.communicate(source)
+            out, err = proc.communicate(source.encode('utf-8'))
+            out = out.decode('utf-8')
+            err = err.decode('utf-8')
             if err:
                 print('FAIL')
                 print('Unexpected output on stderr: {}'.format(err),
index a714af8d236bc41811b7f61fff0767cf0c2b0d62..7939b42f9a2f1369ec990c39ac2e2a41fde628e7 100644 (file)
 # as ['constant', 'float', ['1.000000']].
 
 import re
+import sys
+if sys.version_info >= (3, 0, 0):
+    STRING_TYPE = str
+else:
+    STRING_TYPE = unicode
 
 def check_sexp(sexp):
     """Verify that the argument is a proper sexp.
@@ -39,7 +44,7 @@ def check_sexp(sexp):
     if isinstance(sexp, list):
         for s in sexp:
             check_sexp(s)
-    elif not isinstance(sexp, basestring):
+    elif not isinstance(sexp, (STRING_TYPE, bytes)):
         raise Exception('Not a sexp: {0!r}'.format(sexp))
 
 def parse_sexp(sexp):
@@ -70,8 +75,10 @@ def sexp_to_string(sexp):
     """Convert a sexp, represented as nested lists containing strings,
     into a single string of the form parseable by mesa.
     """
-    if isinstance(sexp, basestring):
+    if isinstance(sexp, STRING_TYPE):
         return sexp
+    if isinstance(sexp, bytes):
+        return sexp.encode('utf-8')
     assert isinstance(sexp, list)
     result = ''
     for s in sexp: