Commit ebae9e61 authored by Dylan Baker's avatar Dylan Baker

python: Convert from print statement to function

One of the biggest changes between python2 and python3 is that print
changed from a statement to a function. This change was backported to
python2 in the __future__ module, and this patch makes that conversation
to ease the transition from python2 to python3.

v2: - Replace dict comprehension with dict(generator). This is for
      python 2.6 compatability
Signed-off-by: Dylan Baker's avatarDylan Baker <baker.dylan.c@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> (v1)
parent dc9345d0
......@@ -22,6 +22,7 @@
# Piglit core
from __future__ import print_function
import errno
import os
import platform
......@@ -204,8 +205,8 @@ def checkDir(dirname, failifexists):
exists = False
if exists and failifexists:
print >>sys.stderr, "%(dirname)s exists already.\nUse --overwrite if" \
"you want to overwrite it.\n" % locals()
print("%(dirname)s exists already.\nUse --overwrite if "
"you want to overwrite it.\n" % locals(), file=sys.stderr)
exit(1)
try:
......
......@@ -24,6 +24,7 @@
# Authors: Tom Stellard <thomas.stellard@amd.com>
#
from __future__ import print_function
import re
import subprocess
from os import path
......@@ -46,7 +47,8 @@ def add_opencv_tests(profile, individual = False):
opencv_test_ocl = path.join(PIGLIT_CONFIG.get('opencv',
'opencv_test_ocl_bindir'), 'opencv_test_ocl')
if not path.isfile(opencv_test_ocl):
print 'Warning: ', opencv_test_ocl, 'does not exist.\nSkipping OpenCV tests...'
print('Warning: {} does not exist.\nSkipping OpenCV '
'tests...'.format(opencv_test_ocl))
return
tests = subprocess.check_output([opencv_test_ocl, '--gtest_list_tests'])
test_list = tests.splitlines()
......
......@@ -23,6 +23,7 @@
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import os
import os.path as path
import re
......
......@@ -18,7 +18,8 @@
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import os
import os.path as path
import itertools
......@@ -462,27 +463,28 @@ class Summary:
if not summary:
if diff:
for test in self.tests['changes']:
print "%(test)s: %(statuses)s" % {'test': test, 'statuses':
print("%(test)s: %(statuses)s" % {'test': test, 'statuses':
' '.join([str(i.tests.get(test, {'result': so.Skip()})
['result']) for i in self.results])}
['result']) for i in self.results])})
else:
for test in self.tests['all']:
print "%(test)s: %(statuses)s" % {'test': test, 'statuses':
print("%(test)s: %(statuses)s" % {'test': test, 'statuses':
' '.join([str(i.tests.get(test, {'result': so.Skip()})
['result']) for i in self.results])}
['result']) for i in self.results])})
# Print the summary
print "summary:"
print " pass: %d" % self.totals['pass']
print " fail: %d" % self.totals['fail']
print " crash: %d" % self.totals['crash']
print " skip: %d" % self.totals['skip']
print " warn: %d" % self.totals['warn']
print " dmesg-warn: %d" % self.totals['dmesg-warn']
print " dmesg-fail: %d" % self.totals['dmesg-fail']
print("summary:\n"
" pass: {pass}\n"
" fail: {fail}\n"
" crash: {crash}\n"
" skip: {skip}\n"
" warn: {warn}\n"
" dmesg-warn: {dmesg-warn}\n"
" dmesg-fail: {dmesg-fail}".format(**self.totals))
if self.tests['changes']:
print " changes: %d" % len(self.tests['changes'])
print " fixes: %d" % len(self.tests['fixes'])
print "regressions: %d" % len(self.tests['regressions'])
print(" changes: {changes}\n"
" fixes: {fixes}\n"
"regressions: {regressions}".format(
**dict((k, len(v)) for k, v in self.tests.iteritems())))
print " total: %d" % sum(self.totals.itervalues())
print(" total: {}".format(sum(self.totals.itervalues())))
......@@ -25,6 +25,7 @@
# Authors:
# Eric Anholt <eric@anholt.net>
from __future__ import print_function
from getopt import getopt, GetoptError
import re
......@@ -38,7 +39,7 @@ Usage %(progName) [cppfile] [add_prefix]
cppfile: path to glean cppfile to parse
add_suffix: prefix to have in test name i.e. glsl1 -> add_glsl1
"""
print USAGE % {'progName': sys.argv[0]}
print(USAGE % {'progName': sys.argv[0]})
sys.exit(1)
......@@ -67,7 +68,7 @@ def main():
break
if not re.match(r'//', name):
name = re.sub(r'".*', r'', name)
print "add_" + suffix + "('" + name + "')"
print("add_" + suffix + "('" + name + "')")
next_is_name = False
if line == " {\n":
next_is_name = True
......
......@@ -22,6 +22,7 @@
# DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import argparse
import sys
import os
......@@ -77,7 +78,7 @@ def main():
profile.prepare_test_list(env)
for name, test in profile.test_list.items():
assert(isinstance(test, ExecTest))
print name, ':::', getCommand(test)
print(name, ':::', getCommand(test))
if __name__ == "__main__":
......
......@@ -21,6 +21,7 @@
# OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import sys
import os
import os.path as path
......
......@@ -22,6 +22,7 @@
# DEALINGS IN THE SOFTWARE.
from __future__ import print_function
import argparse
import sys
import os
......@@ -176,9 +177,9 @@ def main():
json_writer.close_dict()
json_writer.file.close()
print
print 'Thank you for running Piglit!'
print 'Results have been written to ' + result_filepath
print('\n'
'Thank you for running Piglit!\n'
'Results have been written to ' + result_filepath)
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment