Commit a55abb88 authored by Dylan Baker's avatar Dylan Baker

python: use six.{iter,view}{items,keys,values}

This was initially generated via the following sed command:
sed -i \
    -e 's@in \(.*\)\.iter\(values,keys,items\)()@in six.iter\2(\1)@g' \
    -e 's@in \(.*\..*\)\.iter\(values,keys,items\)()@in six.iter\2(\1)@g'

Then cleaned up by hand, including changes for view*.
Signed-off-by: default avatarDylan Baker <dylanx.c.baker@intel.com>
Acked-by: Jose Fonseca's avatarJose Fonseca <jfonseca@vmware.com>
parent b4a47de0
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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'])
)
......
......@@ -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
......
......@@ -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()
......
......@@ -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)
......
......@@ -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))
......
......@@ -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
......
......@@ -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_
......
......@@ -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])))
......
......@@ -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)
......
......@@ -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)
......
......@@ -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
......
......@@ -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
......
<%!
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>
......
......@@ -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
......
......@@ -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.
......
......@@ -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))
......
......@@ -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
......
......@@ -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__':
......
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