PY3 migration(blinkpy unit tests) - Fix blinkpy.web_tests.models unit tests.

most models tests passing, 1 test is flaky.
vpython3 ./run_blinkpy_tests.py blinkpy.web_tests.models

Bug: 1218641


Change-Id: Iba2fc77aa5f1e3de909ee16ca215645746e3834f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3064097
Commit-Queue: Preethi Mohan <preethim@google.com>
Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/master@{#907810}
diff --git a/third_party/blink/tools/blinkpy/web_tests/models/test_configuration.py b/third_party/blink/tools/blinkpy/web_tests/models/test_configuration.py
index 9fbc21c..351ea94b 100644
--- a/third_party/blink/tools/blinkpy/web_tests/models/test_configuration.py
+++ b/third_party/blink/tools/blinkpy/web_tests/models/test_configuration.py
@@ -43,10 +43,10 @@
         return ['version', 'architecture', 'build_type']
 
     def items(self):
-        return self.__dict__.items()
+        return list(self.__dict__.items())
 
     def keys(self):
-        return self.__dict__.keys()
+        return list(self.__dict__.keys())
 
     def __str__(self):
         return (
@@ -63,7 +63,7 @@
 
     def values(self):
         """Returns the configuration values of this instance as a tuple."""
-        return self.__dict__.values()
+        return list(self.__dict__.values())
 
 
 class SpecifierSorter(object):
@@ -100,7 +100,7 @@
         return self._specifier_to_category.get(specifier)
 
     def sort_specifiers(self, specifiers):
-        category_slots = map(lambda x: [], TestConfiguration.category_order())
+        category_slots = [[] for x in TestConfiguration.category_order()]
         for specifier in specifiers:
             category_slots[self.specifier_priority(specifier)].append(
                 specifier)
@@ -177,7 +177,7 @@
                 matching_sets.setdefault(category,
                                          set()).update(configurations)
 
-        return reduce(set.intersection, matching_sets.values())
+        return reduce(set.intersection, list(matching_sets.values()))
 
     @classmethod
     def collapse_macros(cls, macros_dict, specifiers_list):
@@ -276,7 +276,7 @@
 
         # 3) Abbreviate specifier sets by combining specifiers across categories.
         #   (win7, release), (win10, release) --> (win7, win10, release)
-        while try_abbreviating(self._collapsing_sets_by_size.values()):
+        while try_abbreviating(list(self._collapsing_sets_by_size.values())):
             pass
 
         # 4) Substitute specifier subsets that match macros within each set:
diff --git a/third_party/blink/tools/blinkpy/web_tests/models/test_expectations.py b/third_party/blink/tools/blinkpy/web_tests/models/test_expectations.py
index 2967c55..a9d19cd 100644
--- a/third_party/blink/tools/blinkpy/web_tests/models/test_expectations.py
+++ b/third_party/blink/tools/blinkpy/web_tests/models/test_expectations.py
@@ -37,6 +37,7 @@
 from blinkpy.common.memoized import memoized
 from blinkpy.web_tests.models import typ_types
 from typ import expectations_parser
+from functools import reduce
 
 ResultType = typ_types.ResultType
 
@@ -233,9 +234,9 @@
         if lineno_to_exps:
             lines.append(_NotExpectation('', len(content_lines) + 1))
 
-            for line in sorted(
-                    reduce(lambda x,y: x+y, lineno_to_exps.values()),
-                    key=lambda e: e.test):
+            for line in sorted(reduce(lambda x, y: x + y,
+                                      list(lineno_to_exps.values())),
+                               key=lambda e: e.test):
                 if line.lineno:
                     raise ValueError(
                         "Expectation '%s' was given a line number that "
@@ -345,7 +346,7 @@
                                      trailing_comments=trailing_comments)
 
     def get_expectations_from_file(self, path, test_name):
-        idx = self._expectations_dict.keys().index(path)
+        idx = list(self._expectations_dict.keys()).index(path)
         return copy.deepcopy(
             self._expectations[idx].individual_exps.get(test_name) or [])
 
@@ -435,7 +436,7 @@
             path: Absolute path of file where the Expectation instances
                   came from.
             exps: List of Expectation instances to be deleted."""
-        idx = self._expectations_dict.keys().index(path)
+        idx = list(self._expectations_dict.keys()).index(path)
         typ_expectations = self._expectations[idx]
 
         for exp in exps:
@@ -458,7 +459,7 @@
             exps: List of Expectation instances to be added to the file.
             lineno: Line number in expectations file where the expectations will
                     be added."""
-        idx = self._expectations_dict.keys().index(path)
+        idx = list(self._expectations_dict.keys()).index(path)
         typ_expectations = self._expectations[idx]
         added_glob = False
 
@@ -483,7 +484,7 @@
 
         if added_glob:
             glob_exps = reduce(lambda x, y: x + y,
-                               typ_expectations.glob_exps.values())
+                               list(typ_expectations.glob_exps.values()))
             glob_exps.sort(key=lambda e: len(e.test), reverse=True)
             typ_expectations.glob_exps = OrderedDict()
             for exp in glob_exps:
@@ -500,16 +501,17 @@
     def __init__(self, test_expectations):
         self._test_expectations = test_expectations
         self._configuration_specifiers_dict = {}
-        for os, os_versions in (self._test_expectations.port.
-                                configuration_specifier_macros().items()):
+        for os, os_versions in (list(
+                self._test_expectations.port.configuration_specifier_macros(
+                ).items())):
             self._configuration_specifiers_dict[os.lower()] = (frozenset(
                 version.lower() for version in os_versions))
         self._os_specifiers = frozenset(
             os for os in self._configuration_specifiers_dict.keys())
         self._version_specifiers = frozenset(
-            specifier.lower() for specifier in reduce(
-                lambda x, y: x | y, self._configuration_specifiers_dict.
-                values()))
+            specifier.lower() for specifier in
+            reduce(lambda x, y: x | y,
+                   list(self._configuration_specifiers_dict.values())))
         self._deleted_lines = set()
         self._generic_exp_file_path = \
             self._test_expectations.port.path_to_generic_test_expectations_file()
diff --git a/third_party/blink/tools/blinkpy/web_tests/models/test_expectations_unittest.py b/third_party/blink/tools/blinkpy/web_tests/models/test_expectations_unittest.py
index ad8f0dd..c45b924 100644
--- a/third_party/blink/tools/blinkpy/web_tests/models/test_expectations_unittest.py
+++ b/third_party/blink/tools/blinkpy/web_tests/models/test_expectations_unittest.py
@@ -37,6 +37,8 @@
 from blinkpy.web_tests.models.test_expectations import (
     TestExpectations, SystemConfigurationRemover, ParseError)
 from blinkpy.web_tests.models.typ_types import ResultType, Expectation
+from six.moves import range
+from functools import reduce
 
 
 class Base(unittest.TestCase):
@@ -464,7 +466,7 @@
         self.set_up_using_raw_expectations(raw_expectations)
         all_versions = reduce(
             lambda x, y: x + y,
-            self._port.configuration_specifier_macros_dict.values())
+            list(self._port.configuration_specifier_macros_dict.values()))
         self._system_config_remover.remove_os_versions(
             'failures/expected/text.html', all_versions)
         self._system_config_remover.update_expectations()
@@ -484,7 +486,7 @@
         self.set_up_using_raw_expectations(raw_expectations)
         all_versions = reduce(
             lambda x, y: x + y,
-            self._port.configuration_specifier_macros_dict.values())
+            list(self._port.configuration_specifier_macros_dict.values()))
         self._system_config_remover.remove_os_versions(
             'failures/expected/text.html', all_versions)
         self._system_config_remover.update_expectations()
diff --git a/third_party/blink/tools/blinkpy/web_tests/models/test_failures_unittest.py b/third_party/blink/tools/blinkpy/web_tests/models/test_failures_unittest.py
index 1b8dbff..acf0111 100644
--- a/third_party/blink/tools/blinkpy/web_tests/models/test_failures_unittest.py
+++ b/third_party/blink/tools/blinkpy/web_tests/models/test_failures_unittest.py
@@ -102,7 +102,7 @@
             test_failure.result_directory = '/dir'
 
         pass_with_stderr = PassWithStderr(
-            DriverOutput(None, None, None, None, error='pass with stderr'))
+            DriverOutput(None, None, None, None, error=b'pass with stderr'))
         init_test_failure(pass_with_stderr)
         crash = FailureCrash(
             DriverOutput(None,
@@ -110,10 +110,10 @@
                          None,
                          None,
                          crash=True,
-                         error='crash stderr'))
+                         error=b'crash stderr'))
         init_test_failure(crash)
         timeout = FailureTimeout(
-            DriverOutput(None, None, None, None, error='timeout with stderr'))
+            DriverOutput(None, None, None, None, error=b'timeout with stderr'))
         init_test_failure(timeout)
 
         pass_with_stderr.create_artifacts(artifacts)