[Piglit] [PATCH 14/44] python: use six.{iter, view}{items, keys, values}
baker.dylan.c at gmail.com
baker.dylan.c at gmail.com
Wed Jan 27 16:06:22 PST 2016
From: Dylan Baker <baker.dylan.c at gmail.com>
This was initially generated via the following sed command:
sed -i \
-e 's at in \(.*\)\.iter\(values,keys,items\)()@in six.iter\2(\1)@g' \
-e 's at in \(.*\..*\)\.iter\(values,keys,items\)()@in six.iter\2(\1)@g'
Then cleaned up by hand, including changes for view*.
Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
framework/backends/__init__.py | 4 +++-
framework/backends/json.py | 12 +++++++-----
framework/dmesg.py | 2 +-
framework/log.py | 2 +-
framework/options.py | 4 +++-
framework/profile.py | 10 +++++-----
framework/programs/run.py | 4 +++-
framework/programs/summary.py | 4 +++-
framework/results.py | 11 +++++------
framework/summary/common.py | 5 +++--
framework/summary/console_.py | 6 +++---
framework/summary/html_.py | 3 ++-
framework/test/base.py | 8 ++++----
framework/test/deqp.py | 2 +-
templates/index.mako | 5 +++--
templates/testrun_info.mako | 7 +++++--
unittests/backends_tests.py | 3 ++-
unittests/json_results_update_tests.py | 8 +++++---
unittests/results_tests.py | 3 ++-
unittests/summary_console_tests.py | 3 ++-
unittests/utils.py | 4 ++--
21 files changed, 65 insertions(+), 45 deletions(-)
diff --git a/framework/backends/__init__.py b/framework/backends/__init__.py
index 1b814a2..48c7917 100644
--- a/framework/backends/__init__.py
+++ b/framework/backends/__init__.py
@@ -45,6 +45,8 @@ from __future__ import absolute_import, division, print_function
import os
import importlib
+import six
+
from .register import Registry
from .compression import COMPRESSION_SUFFIXES
@@ -160,7 +162,7 @@ def load(file_path):
extension, compression = get_extension(file_path)
- for backend in BACKENDS.itervalues():
+ for backend in six.itervalues(BACKENDS):
if extension in backend.extensions:
loader = backend.load
diff --git a/framework/backends/json.py b/framework/backends/json.py
index 8e4dc13..88702e8 100644
--- a/framework/backends/json.py
+++ b/framework/backends/json.py
@@ -31,6 +31,8 @@ try:
except ImportError:
import json
+import six
+
from framework import status, results, exceptions
from .abstract import FileBackend, write_compressed
from .register import Registry
@@ -348,7 +350,7 @@ def _update_zero_to_one(result):
updated_results = {}
remove = set()
- for name, test in result.tests.iteritems():
+ for name, test in six.iteritems(result.tests):
assert not isinstance(test, results.TestResult), \
'Test was erroniaously turned into a TestResult'
@@ -400,7 +402,7 @@ def _update_zero_to_one(result):
#
# this must be the last thing done in this loop, or there will be pain
if test.get('subtest'):
- for sub in test['subtest'].iterkeys():
+ for sub in six.iterkeys(test['subtest']):
# adding the leading / ensures that we get exactly what we
# expect, since endswith does a character by chacter match, if
# the subtest name is duplicated it wont match, and if there
@@ -528,7 +530,7 @@ def _update_four_to_five(results):
"""Updates json results from version 4 to version 5."""
new_tests = {}
- for name, test in results.tests.iteritems():
+ for name, test in six.iteritems(results.tests):
new_tests[name.replace('/', '@').replace('\\', '@')] = test
results.tests = new_tests
@@ -546,7 +548,7 @@ def _update_five_to_six(result):
"""
new_tests = {}
- for name, test in result.tests.iteritems():
+ for name, test in six.iteritems(result.tests):
new_tests[name] = results.TestResult.from_dict(test)
result.tests = new_tests
@@ -578,7 +580,7 @@ def _update_seven_to_eight(result):
This value is used for both TestResult.time and TestrunResult.time_elapsed.
"""
- for test in result.tests.viewvalues():
+ for test in six.viewvalues(result.tests):
test.time = results.TimeAttribute(end=test.time)
result.time_elapsed = results.TimeAttribute(end=result.time_elapsed)
diff --git a/framework/dmesg.py b/framework/dmesg.py
index 76a3710..c33dd11 100644
--- a/framework/dmesg.py
+++ b/framework/dmesg.py
@@ -141,7 +141,7 @@ class BaseDmesg(object):
result.result = replace(result.result)
# Replace the results of any subtests
- for key, value in result.subtests.iteritems():
+ for key, value in six.iteritems(result.subtests):
result.subtests[key] = replace(value)
# Add the dmesg values to the result
diff --git a/framework/log.py b/framework/log.py
index 86ae575..12ff7ca 100644
--- a/framework/log.py
+++ b/framework/log.py
@@ -165,7 +165,7 @@ class QuietLog(BaseLog):
done=str(self._state['complete']).zfill(self._pad),
total=str(self._state['total']).zfill(self._pad),
status=', '.join('{0}: {1}'.format(k, v) for k, v in
- sorted(self._state['summary'].iteritems())),
+ sorted(six.iteritems(self._state['summary']))),
running=''.join('|/-\\'[x % 4] for x in self._state['running'])
)
diff --git a/framework/options.py b/framework/options.py
index c6d9314..78a020f 100644
--- a/framework/options.py
+++ b/framework/options.py
@@ -30,6 +30,8 @@ import collections
import os
import re
+import six
+
__all__ = ['OPTIONS']
# pylint: disable=too-few-public-methods
@@ -206,7 +208,7 @@ class _Options(object): # pylint: disable=too-many-instance-attributes
self.__init__()
def __iter__(self):
- for key, values in self.__dict__.iteritems():
+ for key, values in six.iteritems(self.__dict__):
if not key.startswith('_'):
yield key, values
diff --git a/framework/profile.py b/framework/profile.py
index b7204ed..d461f23 100644
--- a/framework/profile.py
+++ b/framework/profile.py
@@ -207,7 +207,7 @@ class TestProfile(object):
return True
# Filter out unwanted tests
- self.test_list = dict(item for item in self.test_list.iteritems()
+ self.test_list = dict(item for item in six.iteritems(self.test_list)
if check_all(item))
if not self.test_list:
@@ -276,15 +276,15 @@ class TestProfile(object):
multi = multiprocessing.dummy.Pool()
if options.OPTIONS.concurrent == "all":
- run_threads(multi, self.test_list.iteritems())
+ run_threads(multi, six.iteritems(self.test_list))
elif options.OPTIONS.concurrent == "none":
- run_threads(single, self.test_list.iteritems())
+ run_threads(single, six.iteritems(self.test_list))
else:
# Filter and return only thread safe tests to the threaded pool
- run_threads(multi, (x for x in self.test_list.iteritems()
+ run_threads(multi, (x for x in six.iteritems(self.test_list)
if x[1].run_concurrent))
# Filter and return the non thread safe tests to the single pool
- run_threads(single, (x for x in self.test_list.iteritems()
+ run_threads(single, (x for x in six.iteritems(self.test_list)
if not x[1].run_concurrent))
log.get().summary()
diff --git a/framework/programs/run.py b/framework/programs/run.py
index c4d4770..7fc4d95 100644
--- a/framework/programs/run.py
+++ b/framework/programs/run.py
@@ -28,6 +28,8 @@ import time
import ConfigParser
import ctypes
+import six
+
from framework import core, backends, exceptions, options
import framework.results
import framework.profile
@@ -321,7 +323,7 @@ def resume(input_):
# Don't re-run tests that have already completed, incomplete status tests
# have obviously not completed.
- for name, result in results.tests.iteritems():
+ for name, result in six.iteritems(results.tests):
if args.no_retry or result.result != 'incomplete':
options.OPTIONS.exclude_tests.add(name)
diff --git a/framework/programs/summary.py b/framework/programs/summary.py
index 6cf6121..4137cf3 100644
--- a/framework/programs/summary.py
+++ b/framework/programs/summary.py
@@ -27,6 +27,8 @@ import os.path as path
import sys
import errno
+import six
+
from framework import summary, status, core, backends, exceptions
from . import parsers
@@ -179,7 +181,7 @@ def csv(input_):
testrun = backends.load(args.testResults)
def write_results(output):
- for name, result in testrun.tests.iteritems():
+ for name, result in six.iteritems(testrun.tests):
output.write("{},{},{},{}\n".format(name, result.time,
result.returncode,
result.result))
diff --git a/framework/results.py b/framework/results.py
index f0c0a99..b18dce5 100644
--- a/framework/results.py
+++ b/framework/results.py
@@ -22,7 +22,6 @@
""" Module for results generation """
from __future__ import absolute_import, division, print_function
-
import collections
import copy
import datetime
@@ -176,7 +175,7 @@ class TestResult(object):
"""
if self.subtests:
- return max(self.subtests.itervalues())
+ return max(six.itervalues(self.subtests))
return self.__result
@result.setter
@@ -226,7 +225,7 @@ class TestResult(object):
setattr(inst, each, dict_[each])
if 'subtests' in dict_:
- for name, value in dict_['subtests'].iteritems():
+ for name, value in six.iteritems(dict_['subtests']):
inst.subtests[name] = value
# out and err must be set manually to avoid replacing the setter
@@ -263,7 +262,7 @@ class Totals(dict):
# Since totals are prepopulated, calling 'if not <Totals instance>'
# will always result in True, this will cause it to return True only if
# one of the values is not zero
- for each in self.itervalues():
+ for each in six.itervalues(self):
if each != 0:
return True
return False
@@ -316,11 +315,11 @@ class TestrunResult(object):
def calculate_group_totals(self):
"""Calculate the number of pases, fails, etc at each level."""
- for name, result in self.tests.iteritems():
+ for name, result in six.iteritems(self.tests):
# If there are subtests treat the test as if it is a group instead
# of a test.
if result.subtests:
- for res in result.subtests.itervalues():
+ for res in six.itervalues(result.subtests):
res = str(res)
temp = name
diff --git a/framework/summary/common.py b/framework/summary/common.py
index c72fc3c..e5e670b 100644
--- a/framework/summary/common.py
+++ b/framework/summary/common.py
@@ -26,6 +26,7 @@ from __future__ import absolute_import, division, print_function
import re
import operator
+import six
from six.moves import zip
# a local variable status exists, prevent accidental overloading by renaming
@@ -92,11 +93,11 @@ class Names(object):
"""A set of all tests in all runs."""
all_ = set()
for res in self.__results:
- for key, value in res.tests.iteritems():
+ for key, value in six.iteritems(res.tests):
if not value.subtests:
all_.add(key)
else:
- for subt in value.subtests.iterkeys():
+ for subt in six.iterkeys(value.subtests):
all_.add(grouptools.join(key, subt))
return all_
diff --git a/framework/summary/console_.py b/framework/summary/console_.py
index d219498..b3945d4 100644
--- a/framework/summary/console_.py
+++ b/framework/summary/console_.py
@@ -25,8 +25,8 @@
from __future__ import absolute_import, division, print_function
import textwrap
-# a local variable status exists, prevent accidental overloading by renaming
-# the module
+import six
+
from framework import grouptools, backends
from .common import Results
@@ -83,7 +83,7 @@ def _print_summary(results):
regressions=print_template.format(
*[str(s) for s in results.counts.regressions]),
total=print_template.format(*[
- str(sum(x.totals['root'].itervalues()))
+ str(sum(six.itervalues(x.totals['root'])))
for x in results.results])))
diff --git a/framework/summary/html_.py b/framework/summary/html_.py
index 60d7f5e..d369204 100644
--- a/framework/summary/html_.py
+++ b/framework/summary/html_.py
@@ -31,6 +31,7 @@ import sys
import errno
from mako.lookup import TemplateLookup
+import six
# a local variable status exists, prevent accidental overloading by renaming
# the module
@@ -96,7 +97,7 @@ def _make_testrun_info(results, destination, exclude=None):
lspci=each.lspci))
# Then build the individual test results
- for key, value in each.tests.iteritems():
+ for key, value in six.iteritems(each.tests):
html_path = os.path.join(destination, name,
escape_filename(key + ".html"))
temp_path = os.path.dirname(html_path)
diff --git a/framework/test/base.py b/framework/test/base.py
index af51386..589df1c 100644
--- a/framework/test/base.py
+++ b/framework/test/base.py
@@ -210,7 +210,7 @@ class Test(object):
self.result.command = ' '.join(self.command)
self.result.environment = " ".join(
'{0}="{1}"'.format(k, v) for k, v in itertools.chain(
- options.OPTIONS.env.iteritems(), self.env.iteritems()))
+ six.iteritems(options.OPTIONS.env), six.iteritems(self.env)))
try:
self.is_skip()
@@ -260,9 +260,9 @@ class Test(object):
# requirements.
#
fullenv = dict()
- for key, value in itertools.chain(os.environ.iteritems(),
- options.OPTIONS.env.iteritems(),
- self.env.iteritems()):
+ for key, value in itertools.chain(six.iteritems(os.environ),
+ six.iteritems(options.OPTIONS.env),
+ six.iteritems(self.env)):
fullenv[key] = str(value)
diff --git a/framework/test/deqp.py b/framework/test/deqp.py
index 5b25718..bfe228e 100644
--- a/framework/test/deqp.py
+++ b/framework/test/deqp.py
@@ -150,7 +150,7 @@ class DEQPBaseTest(Test):
# otherwise this requires some break/else/continue madness
for line in self.result.out.split('\n'):
line = line.lstrip()
- for k, v in self.__RESULT_MAP.iteritems():
+ for k, v in six.iteritems(self.__RESULT_MAP):
if line.startswith(k):
self.result.result = v
return
diff --git a/templates/index.mako b/templates/index.mako
index 690206f..39f4976 100644
--- a/templates/index.mako
+++ b/templates/index.mako
@@ -3,6 +3,7 @@
import posixpath # this must be posixpath, since we want /'s not \'s
import re
+ import six
from six.moves import range
from framework import grouptools, status
@@ -23,7 +24,7 @@
return status.NOTRUN
return max([status.status_lookup(s) for s, v in
- result.totals[group].iteritems() if v > 0])
+ six.iteritems(result.totals[group]) if v > 0])
def group_fraction(result, group):
"""Get the fraction value for a group."""
@@ -32,7 +33,7 @@
num = 0
den = 0
- for k, v in result.totals[group].iteritems():
+ for k, v in six.iteritems(result.totals[group]):
if v > 0:
s = status.status_lookup(k)
num += s.fraction[0] * v
diff --git a/templates/testrun_info.mako b/templates/testrun_info.mako
index f8e1b47..473897a 100644
--- a/templates/testrun_info.mako
+++ b/templates/testrun_info.mako
@@ -1,3 +1,6 @@
+<%!
+ import six
+%>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//END"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -21,10 +24,10 @@
<td>totals</td>
<td>
<table>
- % for key, value in sorted(totals.iteritems(), key=lambda (k,v): (v,k), reverse=True):
+ % for key, value in sorted(six.iteritems(totals), key=lambda i: (i[1], i[0]), reverse=True):
<tr><td>${key}</td><td>${value}</td></tr>
% endfor
- <tr><td>total</td><td>${sum(totals.itervalues())}</td></tr>
+ <tr><td>total</td><td>${sum(six.itervalues(totals))}</td></tr>
</table>
</td>
</tr>
diff --git a/unittests/backends_tests.py b/unittests/backends_tests.py
index 54d5e62..a7af795 100644
--- a/unittests/backends_tests.py
+++ b/unittests/backends_tests.py
@@ -26,6 +26,7 @@ from __future__ import absolute_import, division, print_function
import os
import nose.tools as nt
+import six
from framework import backends, options
from . import utils
@@ -77,7 +78,7 @@ def test_get_backend():
def check(n, i):
return nt.assert_is(backends.get_backend(n), i)
- for name, inst in backends_.iteritems():
+ for name, inst in six.iteritems(backends_):
check.description = \
'backends.get_backend({0}): returns {0} backend'.format(name)
yield check, name, inst
diff --git a/unittests/json_results_update_tests.py b/unittests/json_results_update_tests.py
index 33a30bc..85c2d06 100644
--- a/unittests/json_results_update_tests.py
+++ b/unittests/json_results_update_tests.py
@@ -29,7 +29,9 @@ try:
import simplejson as json
except ImportError:
import json
+
import nose.tools as nt
+import six
from . import utils
from framework import backends, results
@@ -164,7 +166,7 @@ class TestV0toV1(object):
def test_info_delete(self):
"""backends.json.update_results (0 -> 1): Remove the info name from results"""
- for value in self.RESULT.tests.itervalues():
+ for value in six.itervalues(self.RESULT.tests):
nt.ok_('info' not in value)
def test_returncode_from_info(self):
@@ -215,12 +217,12 @@ class TestV0toV1(object):
expected = 'group2/groupA/test/subtest 1'
nt.assert_not_in(
- expected, self.RESULT.tests.iterkeys(),
+ expected, six.iterkeys(self.RESULT.tests),
msg='{0} found in result, when it should not be'.format(expected))
def test_handle_fixed_subtests(self):
"""backends.json.update_results (0 -> 1): Correctly handle new single entry subtests correctly"""
- nt.ok_('group3/groupA/test' in self.RESULT.tests.iterkeys())
+ nt.ok_('group3/groupA/test' in six.iterkeys(self.RESULT.tests))
def _load_with_update(self, data=None):
"""If the file is not results.json, it will be renamed.
diff --git a/unittests/results_tests.py b/unittests/results_tests.py
index d40614e..9b03ae8 100644
--- a/unittests/results_tests.py
+++ b/unittests/results_tests.py
@@ -23,6 +23,7 @@
from __future__ import absolute_import, division, print_function
import nose.tools as nt
+import six
from framework import results, status, exceptions, grouptools
from . import utils
@@ -500,7 +501,7 @@ def test_totals_true():
"""results.Totals: bool() returns True when any value is not 0"""
# This might deserve a generator, but it seems so simple that it it's a lot
# of work for no gain
- for key in results.Totals().iterkeys():
+ for key in six.iterkeys(results.Totals()):
test = results.Totals()
test[key] += 1
nt.ok_(bool(test), msg='Returns false with status {}'.format(key))
diff --git a/unittests/summary_console_tests.py b/unittests/summary_console_tests.py
index 507a551..5b097f1 100644
--- a/unittests/summary_console_tests.py
+++ b/unittests/summary_console_tests.py
@@ -31,6 +31,7 @@ from __future__ import absolute_import, division, print_function
import sys
import nose.tools as nt
+import six
from six.moves import cStringIO as StringIO
from . import utils
@@ -131,7 +132,7 @@ class Test_print_summary(object):
description = "summary.console_._print_summary: calculates {} correctly"
- for key, value in self._ENUMS.iteritems():
+ for key, value in six.iteritems(self._ENUMS):
test.description = description.format(key)
yield test, value
diff --git a/unittests/utils.py b/unittests/utils.py
index 8589953..2b539b9 100644
--- a/unittests/utils.py
+++ b/unittests/utils.py
@@ -420,7 +420,7 @@ def set_env(**envargs):
def _inner(*args, **kwargs):
"""The returned function."""
backup = {}
- for key, value in envargs.iteritems():
+ for key, value in six.iteritems(envargs):
backup[key] = os.environ.get(key, "__DONOTRESTORE__")
if value is not None:
os.environ[key] = value
@@ -430,7 +430,7 @@ def set_env(**envargs):
try:
func(*args, **kwargs)
finally:
- for key, value in backup.iteritems():
+ for key, value in six.iteritems(backup):
if value == "__DONOTRESTORE__" and key in os.environ:
del os.environ[key]
elif value != '__DONOTRESTORE__':
--
2.7.0
More information about the Piglit
mailing list