Commit c5c60391 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[tools] Use absolute imports in testrunner

It also updates the scripts to support Python3

Bug: chromium:1245634
Change-Id: Iffe29bacfd788575b35da6449d5830fc665da7a8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3194259
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77155}
parent 129ef0a1
......@@ -376,7 +376,7 @@ class BaseTestRunner(object):
# Progress
parser.add_option("-p", "--progress",
choices=list(PROGRESS_INDICATORS), default="mono",
choices=list(PROGRESS_INDICATORS.keys()), default="mono",
help="The style of progress indicator (verbose, dots, "
"color, mono)")
parser.add_option("--json-test-results",
......@@ -530,7 +530,7 @@ class BaseTestRunner(object):
options.j = multiprocessing.cpu_count()
options.command_prefix = shlex.split(options.command_prefix)
options.extra_flags = sum(map(shlex.split, options.extra_flags), [])
options.extra_flags = sum(list(map(shlex.split, options.extra_flags)), [])
def _process_options(self, options):
pass
......@@ -617,7 +617,7 @@ class BaseTestRunner(object):
def expand_test_group(name):
return TEST_MAP.get(name, [name])
return reduce(list.__add__, map(expand_test_group, args), [])
return reduce(list.__add__, list(map(expand_test_group, args)), [])
def _args_to_suite_names(self, args, test_root):
# Use default tests if no test configuration was provided at the cmd line.
......@@ -780,7 +780,7 @@ class BaseTestRunner(object):
raise NotImplementedError()
def _prepare_procs(self, procs):
procs = filter(None, procs)
procs = list([_f for _f in procs if _f])
for i in range(0, len(procs) - 1):
procs[i].connect_to(procs[i + 1])
procs[0].setup()
......
......@@ -32,8 +32,8 @@ from __future__ import absolute_import
import os
import re
from .variants import ALL_VARIANTS
from .utils import Freeze
from testrunner.local.variants import ALL_VARIANTS
from testrunner.local.utils import Freeze
# Possible outcomes
FAIL = "FAIL"
......@@ -131,8 +131,8 @@ class StatusFile(object):
for variant in variants:
for rule, value in (
list(self._rules.get(variant, {}).iteritems()) +
list(self._prefix_rules.get(variant, {}).iteritems())):
list(self._rules.get(variant, {}).items()) +
list(self._prefix_rules.get(variant, {}).items())):
if (rule, variant) not in used_rules:
if variant == '':
variant_desc = 'variant independent'
......@@ -161,7 +161,7 @@ def _EvalExpression(exp, variables):
try:
return eval(exp, variables)
except NameError as e:
identifier = re.match("name '(.*)' is not defined", e.message).group(1)
identifier = re.match("name '(.*)' is not defined", str(e)).group(1)
assert identifier == "variant", "Unknown identifier: %s" % identifier
return VARIANT_EXPRESSION
......@@ -283,7 +283,7 @@ def ReadStatusFile(content, variables):
def _ReadSection(section, variables, rules, prefix_rules):
assert type(section) == dict
for rule, outcome_list in section.items():
for rule, outcome_list in list(section.items()):
assert type(rule) == str
if rule[-1] == '*':
......
......@@ -223,7 +223,7 @@ class TestGenerator(object):
return self
def __next__(self):
return next(self)
return self.next()
def next(self):
return next(self._iterator)
......
......@@ -212,7 +212,7 @@ class FrozenDict(dict):
def Freeze(obj):
if isinstance(obj, dict):
return FrozenDict((k, Freeze(v)) for k, v in obj.iteritems())
return FrozenDict((k, Freeze(v)) for k, v in list(obj.items()))
elif isinstance(obj, set):
return frozenset(obj)
elif isinstance(obj, list):
......
......@@ -30,14 +30,14 @@ import os
import re
import shlex
from ..outproc import base as outproc
from ..local import command
from ..local import statusfile
from ..local import utils
from ..local.variants import ALL_VARIANT_FLAGS
from ..local.variants import INCOMPATIBLE_FLAGS_PER_VARIANT
from ..local.variants import INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE
from ..local.variants import INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG
from testrunner.outproc import base as outproc
from testrunner.local import command
from testrunner.local import statusfile
from testrunner.local import utils
from testrunner.local.variants import ALL_VARIANT_FLAGS
from testrunner.local.variants import INCOMPATIBLE_FLAGS_PER_VARIANT
from testrunner.local.variants import INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE
from testrunner.local.variants import INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG
FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)")
......@@ -75,6 +75,13 @@ except NameError:
def cmp(x, y): # Python 3
return (x > y) - (x < y)
def read_file_utf8(file):
try: # Python 3
with open(file, encoding='utf-8') as f:
return f.read()
except TypeError: # Python 2
with open(file) as f:
return f.read()
class TestCase(object):
def __init__(self, suite, path, name, test_config):
......@@ -130,8 +137,8 @@ class TestCase(object):
return not is_flag(outcome)
outcomes = self.suite.statusfile.get_outcomes(self.name, self.variant)
self._statusfile_outcomes = filter(not_flag, outcomes)
self._statusfile_flags = filter(is_flag, outcomes)
self._statusfile_outcomes = list(filter(not_flag, outcomes))
self._statusfile_flags = list(filter(is_flag, outcomes))
self._expected_outcomes = (
self._parse_status_file_outcomes(self._statusfile_outcomes))
......@@ -407,8 +414,7 @@ class TestCase(object):
return self._get_source_path() is not None
def get_source(self):
with open(self._get_source_path()) as f:
return f.read()
return read_file_utf8(self._get_source_path())
def _get_source_path(self):
return None
......@@ -454,8 +460,7 @@ class D8TestCase(TestCase):
"""Returns for a given file a list of absolute paths of files needed by the
given file.
"""
with open(file) as f:
source = f.read()
source = read_file_utf8(file)
result = []
def add_path(path):
result.append(os.path.abspath(path.replace('/', os.path.sep)))
......
......@@ -16,7 +16,7 @@ import sys
import tempfile
# Adds testrunner to the path hence it has to be imported at the beggining.
from . import base_runner
import testrunner.base_runner as base_runner
from testrunner.local import utils
from testrunner.local.variants import ALL_VARIANTS
......
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