[Piglit] [PATCH 4/5] generated_tests: Convert to python3
Dylan Baker
baker.dylan.c at gmail.com
Mon Feb 24 11:42:41 PST 2014
This uses python3 for generating tests. This was generated by the 2to3
tool, with a few hand tuned changes, mainly around print statements that
already used grouping parens.
---
generated_tests/builtin_function.py | 8 ++++----
generated_tests/gen_builtin_uniform_tests.py | 20 +++++++++-----------
generated_tests/gen_constant_array_size_tests.py | 8 ++++----
generated_tests/gen_interpolation_tests.py | 6 +++---
generated_tests/gen_non-lvalue_tests.py | 2 +-
generated_tests/gen_shader_bit_encoding_tests.py | 10 +++++-----
generated_tests/gen_texture_query_lod_tests.py | 10 +++++-----
generated_tests/gen_uniform_initializer_tests.py | 4 ++--
generated_tests/genclbuiltins.py | 6 +++---
generated_tests/generate-cl-int-builtins.py | 14 +++++++-------
generated_tests/generate-cl-store-tests.py | 2 +-
.../interpolation-qualifier-built-in-variable.py | 10 +++++-----
tests/util/gen_dispatch.py | 2 +-
13 files changed, 50 insertions(+), 52 deletions(-)
diff --git a/generated_tests/builtin_function.py b/generated_tests/builtin_function.py
index fc25ce1..7b059a8 100644
--- a/generated_tests/builtin_function.py
+++ b/generated_tests/builtin_function.py
@@ -644,9 +644,9 @@ def _vectorize_test_vectors(test_vectors, scalar_arg_indices, vector_length):
vectors, wrap around as necessary to ensure that every input
test vector is included.
"""
- for i in xrange(0, len(test_vectors), partition_size):
+ for i in range(0, len(test_vectors), partition_size):
partition = []
- for j in xrange(partition_size):
+ for j in range(partition_size):
partition.append(test_vectors[(i + j) % len(test_vectors)])
yield partition
@@ -658,7 +658,7 @@ def _vectorize_test_vectors(test_vectors, scalar_arg_indices, vector_length):
"""
arity = len(test_vectors[0].arguments)
arguments = []
- for j in xrange(arity):
+ for j in range(arity):
if j in scalar_arg_indices:
arguments.append(test_vectors[0].arguments[j])
else:
@@ -692,7 +692,7 @@ def _store_test_vector(test_suite_dict, name, glsl_version, extension, test_vect
Signature objects generated.
"""
if template is None:
- arg_indices = xrange(len(test_vector.arguments))
+ arg_indices = range(len(test_vector.arguments))
template = '{0}({1})'.format(
name, ', '.join('{{{0}}}'.format(i) for i in arg_indices))
rettype = glsl_type_of(test_vector.result)
diff --git a/generated_tests/gen_builtin_uniform_tests.py b/generated_tests/gen_builtin_uniform_tests.py
index 5ecfc87..63e4111 100644
--- a/generated_tests/gen_builtin_uniform_tests.py
+++ b/generated_tests/gen_builtin_uniform_tests.py
@@ -103,11 +103,10 @@ def shader_runner_type(glsl_type):
return str(glsl_type)
-class Comparator(object):
+class Comparator(object, metaclass=abc.ABCMeta):
"""Base class which abstracts how we compare expected and actual
values.
"""
- __metaclass__ = abc.ABCMeta
def make_additional_declarations(self):
"""Return additional declarations, if any, that are needed in
@@ -279,12 +278,12 @@ class FloatComparator(Comparator):
col_indexers = ['']
else:
col_indexers = ['[{0}]'.format(i)
- for i in xrange(self.__signature.rettype.num_cols)]
+ for i in range(self.__signature.rettype.num_cols)]
if self.__signature.rettype.num_rows == 1:
row_indexers = ['']
else:
row_indexers = ['[{0}]'.format(i)
- for i in xrange(self.__signature.rettype.num_rows)]
+ for i in range(self.__signature.rettype.num_rows)]
return [col_indexer + row_indexer
for col_indexer in col_indexers
for row_indexer in row_indexers]
@@ -321,13 +320,12 @@ class FloatComparator(Comparator):
return test
-class ShaderTest(object):
+class ShaderTest(object, metaclass=abc.ABCMeta):
"""Class used to build a test of a single built-in. This is an
abstract base class--derived types should override test_prefix(),
make_vertex_shader(), make_fragment_shader(), and other functions
if necessary.
"""
- __metaclass__ = abc.ABCMeta
def __init__(self, signature, test_vectors, use_if):
"""Prepare to build a test for a single built-in. signature
@@ -418,7 +416,7 @@ class ShaderTest(object):
if self._signature.extension:
shader += '#extension GL_{0} : require\n'.format(self._signature.extension)
shader += additional_declarations
- for i in xrange(len(self._signature.argtypes)):
+ for i in range(len(self._signature.argtypes)):
shader += 'uniform {0} arg{1};\n'.format(
self._signature.argtypes[i], i)
shader += self._comparator.make_additional_declarations()
@@ -428,7 +426,7 @@ class ShaderTest(object):
shader += prefix_statements
invocation = self._signature.template.format(
*['arg{0}'.format(i)
- for i in xrange(len(self._signature.argtypes))])
+ for i in range(len(self._signature.argtypes))])
shader += self._comparator.make_result_handler(invocation, output_var)
shader += suffix_statements
shader += '}\n'
@@ -440,7 +438,7 @@ class ShaderTest(object):
"""
test = ''
for test_num, test_vector in enumerate(self._test_vectors):
- for i in xrange(len(test_vector.arguments)):
+ for i in range(len(test_vector.arguments)):
test += 'uniform {0} arg{1} {2}\n'.format(
shader_runner_type(self._signature.argtypes[i]),
i, shader_runner_format(
@@ -622,7 +620,7 @@ class FragmentShaderTest(ShaderTest):
def all_tests():
for use_if in [False, True]:
- for signature, test_vectors in sorted(test_suite.items()):
+ for signature, test_vectors in test_suite.items():
if use_if and signature.rettype != glsl_bool:
continue
yield VertexShaderTest(signature, test_vectors, use_if)
@@ -643,7 +641,7 @@ def main():
for test in all_tests():
if not options.names_only:
test.generate_shader_test()
- print test.filename()
+ print(test.filename())
if __name__ == '__main__':
diff --git a/generated_tests/gen_constant_array_size_tests.py b/generated_tests/gen_constant_array_size_tests.py
index 59e14c2..e837dda 100644
--- a/generated_tests/gen_constant_array_size_tests.py
+++ b/generated_tests/gen_constant_array_size_tests.py
@@ -113,7 +113,7 @@ class ParserTest(object):
# is safe to use pow() here because its behavior is
# verified in the pow() tests.
terms = []
- for col in xrange(self.__signature.rettype.num_cols):
+ for col in range(self.__signature.rettype.num_cols):
terms.append('pow(distance({0}[{1}], {2}), 2)'.format(
invocation, col,
glsl_constant(test_vector.result[:, col])))
@@ -132,7 +132,7 @@ class ParserTest(object):
# Don't use the equal() function to test itself.
assert self.__signature.rettype.is_vector
terms = []
- for row in xrange(self.__signature.rettype.num_rows):
+ for row in range(self.__signature.rettype.num_rows):
terms.append('{0}[{1}] == {2}'.format(
invocation, row,
glsl_constant(test_vector.result[row])))
@@ -241,7 +241,7 @@ class FragmentParserTest(ParserTest):
def all_tests():
- for signature, test_vectors in sorted(test_suite.items()):
+ for signature, test_vectors in test_suite.items():
yield VertexParserTest(signature, test_vectors)
yield GeometryParserTest(signature, test_vectors)
yield FragmentParserTest(signature, test_vectors)
@@ -262,7 +262,7 @@ def main():
for test in all_tests():
if not options.names_only:
test.generate_parser_test()
- print test.filename()
+ print(test.filename())
if __name__ == '__main__':
diff --git a/generated_tests/gen_interpolation_tests.py b/generated_tests/gen_interpolation_tests.py
index 3bc8ffc..d812c93 100644
--- a/generated_tests/gen_interpolation_tests.py
+++ b/generated_tests/gen_interpolation_tests.py
@@ -196,8 +196,8 @@ class Test(object):
# corners so that rounding does not cause us to accidentally
# probe a pixel that's outside the triangle.
num_subdivisions = 6
- for i in xrange(1, num_subdivisions - 1):
- for j in xrange(1, num_subdivisions - i):
+ for i in range(1, num_subdivisions - 1):
+ for j in range(1, num_subdivisions - i):
# Compute 3D barycentric coordinates--these will be
# used to compute the expected interpolated values
# when using smooth (perspective-correct)
@@ -344,7 +344,7 @@ def all_tests():
def main():
for test in all_tests():
test.generate()
- print test.filename()
+ print(test.filename())
if __name__ == '__main__':
diff --git a/generated_tests/gen_non-lvalue_tests.py b/generated_tests/gen_non-lvalue_tests.py
index 0b545bb..b360ccb 100644
--- a/generated_tests/gen_non-lvalue_tests.py
+++ b/generated_tests/gen_non-lvalue_tests.py
@@ -157,7 +157,7 @@ def all_tests():
def main():
for test in all_tests():
test.generate()
- print test.filename()
+ print(test.filename())
if __name__ == '__main__':
diff --git a/generated_tests/gen_shader_bit_encoding_tests.py b/generated_tests/gen_shader_bit_encoding_tests.py
index d63d86d..a666049 100644
--- a/generated_tests/gen_shader_bit_encoding_tests.py
+++ b/generated_tests/gen_shader_bit_encoding_tests.py
@@ -200,7 +200,7 @@ template = Template(dedent("""\
-1.0 1.0
[test]
- % for name, data in sorted(test_data.iteritems()):
+ % for name, data in sorted(test_data.items()):
% if name == '-0.0' and in_modifier_func != '' and func == 'intBitsToFloat':
# ${in_modifier_func}(INT_MIN) doesn't fit in a 32-bit int. Cannot test.
% else:
@@ -214,11 +214,11 @@ template = Template(dedent("""\
% endfor
"""))
-for api, requirement in requirements.iteritems():
+for api, requirement in requirements.items():
version = requirement['version']
extensions = [requirement['extension']] if requirement['extension'] else []
- for func, attrib in funcs.iteritems():
+ for func, attrib in funcs.items():
in_func = attrib['in_func']
out_func = attrib['out_func']
input_type = attrib['input']
@@ -227,7 +227,7 @@ for api, requirement in requirements.iteritems():
for execution_stage in ('vs', 'fs'):
file_extension = 'frag' if execution_stage == 'fs' else 'vert'
- for in_modifier_func, modifier_func in modifier_funcs.iteritems():
+ for in_modifier_func, modifier_func in modifier_funcs.items():
# Modifying the sign of an unsigned number doesn't make sense.
if func == 'uintBitsToFloat' and in_modifier_func != '':
continue
@@ -240,7 +240,7 @@ for api, requirement in requirements.iteritems():
"{0}-{1}{2}.shader_test".format(execution_stage,
func,
modifier_name))
- print filename
+ print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
diff --git a/generated_tests/gen_texture_query_lod_tests.py b/generated_tests/gen_texture_query_lod_tests.py
index 99a6628..23cc4ee 100755
--- a/generated_tests/gen_texture_query_lod_tests.py
+++ b/generated_tests/gen_texture_query_lod_tests.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python3
# coding=utf-8
#
# Copyright © 2013 Intel Corporation
@@ -89,7 +89,7 @@ template = Template(dedent("""\
* [end config]
*/
- #version ${version.translate(None, '.')}
+ #version ${version.translate({ord('.'): None})}
% for extension in extensions:
#extension ${extension} : enable
% endfor
@@ -111,10 +111,10 @@ template = Template(dedent("""\
}
"""))
-for api, requirement in requirements.iteritems():
+for api, requirement in requirements.items():
Lod = 'Lod' if api == 'glsl-4.00' else 'LOD'
- for sampler_type, coord_type in sampler_type_to_coord_type.iteritems():
+ for sampler_type, coord_type in sampler_type_to_coord_type.items():
for execution_stage in ("vs", "fs"):
file_extension = 'frag' if execution_stage == 'fs' else 'vert'
filename = os.path.join("spec",
@@ -124,7 +124,7 @@ for api, requirement in requirements.iteritems():
"textureQuery{0}-{1}.{2}".format(Lod,
sampler_type,
file_extension))
- print filename
+ print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
diff --git a/generated_tests/gen_uniform_initializer_tests.py b/generated_tests/gen_uniform_initializer_tests.py
index 9474e7b..90ee0f1 100644
--- a/generated_tests/gen_uniform_initializer_tests.py
+++ b/generated_tests/gen_uniform_initializer_tests.py
@@ -67,7 +67,7 @@ def generate_tests(type_list, base_name, major, minor):
'execution',
'uniform-initializer',
'{0}-{1}{2}.shader_test'.format(target, base_name, t))
- print test_file_name
+ print(test_file_name)
dirname = os.path.dirname(test_file_name)
if not os.path.exists(dirname):
@@ -128,7 +128,7 @@ def generate_array_tests(type_list, base_name, major, minor):
'execution',
'uniform-initializer',
'{0}-{1}-array.shader_test'.format(target, base_name))
- print test_file_name
+ print(test_file_name)
dirname = os.path.dirname(test_file_name)
if not os.path.exists(dirname):
diff --git a/generated_tests/genclbuiltins.py b/generated_tests/genclbuiltins.py
index 721191e..3f1575c 100644
--- a/generated_tests/genclbuiltins.py
+++ b/generated_tests/genclbuiltins.py
@@ -252,7 +252,7 @@ def getValue(type, val):
getValue(type, val[3]), getValue(type, val[4]))
# At this point, we should have been passed a number
- if (isinstance(val, (int, long, float))):
+ if (isinstance(val, (int, float))):
return val
print('Invalid value '+repr(val)+' encountered in getValue\n')
@@ -342,12 +342,12 @@ def gen(types, minVersions, functions, testDefs, dirName):
for dataType in types:
for fnName in functions:
# Merge all of the generic/signed/unsigned/custom test definitions
- if not testDefs.has_key((dataType, fnName)):
+ if (dataType, fnName) not in testDefs:
continue
functionDef = testDefs[(dataType, fnName)]
# Check if the function actually exists for this data type
- if (not functionDef.keys()):
+ if (not list(functionDef.keys())):
continue
clcVersionMin = minVersions[fnName]
diff --git a/generated_tests/generate-cl-int-builtins.py b/generated_tests/generate-cl-int-builtins.py
index 52184ad..bca31b7 100755
--- a/generated_tests/generate-cl-int-builtins.py
+++ b/generated_tests/generate-cl-int-builtins.py
@@ -1,4 +1,4 @@
-# !/usr/bin/env python
+# !/usr/bin/env python3
import os
from genclbuiltins import gen, DATA_SIZES, MAX_VALUES, MAX, MIN, BMIN, BMAX, \
@@ -86,7 +86,7 @@ def clz(type, val):
def div(val1, val2):
- return val1 / val2
+ return val1 // val2
def mad_hi(x, y, z, type):
@@ -116,7 +116,7 @@ def pow(val, pow):
def rotate_right(x, n, bits):
# Find all bits that will wrap
- mask = (2L**n) - 1
+ mask = (2**n) - 1
wrapped_bits = x & mask
# sign extension needs to be masked out
@@ -535,12 +535,12 @@ def mergedTestDefinition(dataType, fnName):
def getFnNames():
fnNames = []
- fnNames += generic_tests.keys()
- fnNames += signed_generic_tests.keys()
- fnNames += unsigned_generic_tests.keys()
+ fnNames += list(generic_tests.keys())
+ fnNames += list(signed_generic_tests.keys())
+ fnNames += list(unsigned_generic_tests.keys())
for type in DATA_TYPES:
if (type in builtins):
- fnNames += builtins[type].keys()
+ fnNames += list(builtins[type].keys())
# Get the sorted unique set of function names
return sorted(list(set(fnNames)))
diff --git a/generated_tests/generate-cl-store-tests.py b/generated_tests/generate-cl-store-tests.py
index 5a09985..0151be1 100644
--- a/generated_tests/generate-cl-store-tests.py
+++ b/generated_tests/generate-cl-store-tests.py
@@ -37,7 +37,7 @@ if not os.path.exists(dirName):
def gen_array(size):
- return ' '.join([str(i) for i in xrange(size * 8)])
+ return ' '.join([str(i) for i in range(size * 8)])
def ext_req(type_name):
if type_name[:6] == "double":
diff --git a/generated_tests/interpolation-qualifier-built-in-variable.py b/generated_tests/interpolation-qualifier-built-in-variable.py
index b7edfb7..e85dc77 100644
--- a/generated_tests/interpolation-qualifier-built-in-variable.py
+++ b/generated_tests/interpolation-qualifier-built-in-variable.py
@@ -111,7 +111,7 @@ for fs_mode in interpolation_modes:
var,
fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
- print filename
+ print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
@@ -174,7 +174,7 @@ for vs_mode in interpolation_modes:
'{0}-{1}-unused-{2}.shader_test'.format(vs_mode,
var,
vertex_shader_to_fragment_shader_variable_map[var]))
- print filename
+ print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
@@ -235,7 +235,7 @@ for fs_mode in interpolation_modes:
'unused-{0}-{1}-{2}.shader_test'.format(var,
fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
- print filename
+ print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
@@ -306,7 +306,7 @@ for fs_mode in interpolation_modes:
var,
fs_mode,
vertex_shader_to_fragment_shader_variable_map[var]))
- print filename
+ print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
@@ -375,7 +375,7 @@ for fs_mode in interpolation_modes:
this_side,
fs_mode,
other_side))
- print filename
+ print(filename)
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
diff --git a/tests/util/gen_dispatch.py b/tests/util/gen_dispatch.py
index c97af94..1b64f50 100644
--- a/tests/util/gen_dispatch.py
+++ b/tests/util/gen_dispatch.py
@@ -522,7 +522,7 @@ def generate_resolve_function(ds):
resolve_fn += '\t{0}\n'.format(condition_code_pairs[0][1])
else:
resolve_fn += '\tif ({0})\n\t\t{1}\n'.format(*condition_code_pairs[0])
- for i in xrange(1, len(condition_code_pairs)):
+ for i in range(1, len(condition_code_pairs)):
if condition_code_pairs[i][0] == 'true':
resolve_fn += '\telse\n\t\t{0}\n'.format(
condition_code_pairs[i][1])
--
1.9.0
More information about the Piglit
mailing list