compiler/glsl/tests: Make tests python3 safe
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>
This commit is contained in:
@@ -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]]]
|
||||
|
||||
|
||||
|
@@ -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),
|
||||
|
@@ -28,6 +28,11 @@
|
||||
# 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:
|
||||
|
Reference in New Issue
Block a user