Skip to content

Commit

Permalink
Reland "[CodeHealth] Migrate remainder of testing/ to Python3 compatible
Browse files Browse the repository at this point in the history
syntax"

This is a reland of commit 8defc6c

Uses `sys.path.append(...)` to import the `common` module in
testing/scripts/run_variations_smoke_tests.py (as is done elsewhere in
the original CL) and resolve errors thrown for attempting a relative
import with no known parent package.

Original change's description:
>and Pylint2.7, and fix resulting errors.
>
>Bug: 1262363
>Change-Id: I09628427dd4caf9d873f3b489b897054430f8567
>Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/ /3557490
>Reviewed-by: Ben Pastene <[email protected]>
>Commit-Queue: Joshua Hood <[email protected]>
>Cr-Commit-Position: refs/heads/main@{#996200}

Bug: 1262363
Change-Id: I60fe062f62962d0b3dc4e93d9e29626ed181f688
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/ /3610783
Reviewed-by: Ben Pastene <[email protected]>
Commit-Queue: Joshua Hood <[email protected]>
Cr-Commit-Position: refs/heads/main@{#999432}
  • Loading branch information
hoodjoshua authored and Chromium LUCI CQ committed May 4, 2022
1 parent ca27f06 commit 3fade1f
Show file tree
Hide file tree
Showing 51 changed files with 240 additions and 128 deletions.
19 changes: 3 additions & 16 deletions testing/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,9 @@ def CommonChecks(input_api, output_api):
input_api,
output_api,
'.',
[r'^. _unittest\.py$']))
[r'^. _unittest\.py$'],
run_on_python3=USE_PYTHON3,
skip_shebang_check=True))
output.extend(input_api.canned_checks.RunUnitTestsInDirectory(
input_api,
output_api,
Expand All @@ -36,21 38,6 @@ def CommonChecks(input_api, output_api):
output.extend(input_api.canned_checks.RunPylint(
input_api,
output_api,
files_to_skip=[r'gmock.*', r'gtest.*',
r'buildbot.*', r'merge_scripts.*', r'trigger_scripts.*',
r'unexpected_passes_common.*',
r'clusterfuzz.*',
r'libfuzzer.*']))
# Pylint2.7 is run on subdirs whose presubmit checks are migrated to Python3
output.extend(input_api.canned_checks.RunPylint(
input_api,
output_api,
files_to_check=[r'buildbot.*\.py$',
r'merge_scripts.*\.py$',
r'trigger_scripts.*\.py$',
r'unexpected_passes_common.*\.py$',
r'clusterfuzz.*\.py$',
r'libfuzzer.*\.py$'],
version='2.7'))

return output
Expand Down
Empty file added testing/__init__.py
Empty file.
6 changes: 5 additions & 1 deletion testing/buildbot/PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 3,14 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import sys
import time
import unittest

import PRESUBMIT
# Add src/testing/ into sys.path for importing PRESUBMIT without pylint errors.
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from buildbot import PRESUBMIT


class PresubmitError:
Expand Down
Empty file added testing/buildbot/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion testing/chromoting/browser_tests_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 85,7 @@ def LaunchBTCommand(args, command):
retries = 1
time.sleep(30)
continue
elif jids_used:
if jids_used:
print('JID used by test matched me2me host JID: %s' % host_jid)
else:
# There wasn't a mismatch and no JIDs were returned. If no JIDs were
Expand Down
Empty file added testing/scripts/__init__.py
Empty file.
6 changes: 4 additions & 2 deletions testing/scripts/blink_lint_expectations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 7,10 @@
import os
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
6 changes: 4 additions & 2 deletions testing/scripts/blink_python_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 7,10 @@
import os
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
6 changes: 4 additions & 2 deletions testing/scripts/check_gn_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 7,10 @@
import os
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
6 changes: 4 additions & 2 deletions testing/scripts/check_network_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 12,10 @@
import os
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
5 changes: 4 additions & 1 deletion testing/scripts/check_static_initializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 11,10 @@
import subprocess
import sys

import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common

# A list of files that are allowed to have static initializers.
# If something adds a static initializer, revert it. We don't accept regressions
Expand Down
7 changes: 5 additions & 2 deletions testing/scripts/checkbins.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 21,14 @@
import os
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common

WIN_PY3_TARGETS = ['python3.exe', 'python3.bat']


def with_python3():
if sys.version_info.major >= 3:
return sys.executable
Expand Down
5 changes: 4 additions & 1 deletion testing/scripts/checkdeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,10 @@
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
5 changes: 4 additions & 1 deletion testing/scripts/checklicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,10 @@
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
5 changes: 4 additions & 1 deletion testing/scripts/checkperms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,10 @@
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
7 changes: 5 additions & 2 deletions testing/scripts/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 18,8 @@
logging.basicConfig(level=logging.INFO)

# Add src/testing/ into sys.path for importing xvfb and test_env.
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import test_env
if sys.platform.startswith('linux'):
import xvfb
Expand Down Expand Up @@ -65,6 66,8 @@
'\\ALL RESTRICTED APPLICATION PACKAGES:(I)(OI)(CI)(RX)'
]

# pylint: disable=useless-object-inheritance


def set_lpac_acls(acl_dir, is_test_script=False):
"""Sets LPAC ACLs on a directory. Windows 10 only."""
Expand Down Expand Up @@ -231,7 234,7 @@ def convert_trie_to_flat_paths(trie, prefix=None):
passing_statuses = ('PASS', 'SLOW', 'NEEDSREBASELINE')

for test, result in convert_trie_to_flat_paths(
json_results['tests']).iteritems():
json_results['tests']).items():
key = 'unexpected_' if result.get('is_unexpected') else ''
data = result['actual']
actual_results = data.split()
Expand Down
8 changes: 4 additions & 4 deletions testing/scripts/content_shell_crash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 9,11 @@
import sys


import common

# Add src/testing/ into sys.path for importing xvfb.
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
# Add src/testing/ into sys.path for importing xvfb and common.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import xvfb
from scripts import common


# Unfortunately we need to copy these variables from ../test_env.py.
Expand Down
5 changes: 4 additions & 1 deletion testing/scripts/count_filtered_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,10 @@
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def ParseTestList(test_list_contents):
Expand Down
11 changes: 9 additions & 2 deletions testing/scripts/get_compile_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 8,10 @@
import os
import sys

import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main(argv):
Expand Down Expand Up @@ -51,7 54,11 @@ def main(argv):
return rc

with open(tempfile_path) as f:
results[filename] = json.load(f)
# json.load() throws a ValueError for empty files
try:
results[filename] = json.load(f)
except ValueError:
pass

with open(args.output, 'w') as f:
json.dump(results, f)
Expand Down
9 changes: 8 additions & 1 deletion testing/scripts/gpu_integration_test_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,14 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import common
import os
import sys

# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


class GpuIntegrationTestAdapater(common.BaseIsolatedScriptArgsAdapter):

Expand Down
5 changes: 4 additions & 1 deletion testing/scripts/grit_python_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 11,10 @@
import os
import sys

import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
8 changes: 5 additions & 3 deletions testing/scripts/headless_python_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 7,18 @@
import os
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
typ_path = os.path.abspath(os.path.join(
os.path.dirname(__file__), os.path.pardir, os.path.pardir,
'third_party', 'catapult', 'third_party', 'typ'))
_AddToPathIfNeeded(typ_path)
import typ
import typ #pylint: disable=import-outside-toplevel

top_level_dir = os.path.join(
common.SRC_DIR, 'headless', 'lib', 'browser', 'devtools_api')
Expand Down
7 changes: 5 additions & 2 deletions testing/scripts/host_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 9,10 @@
import platform
import sys

import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def is_linux():
Expand Down Expand Up @@ -88,7 91,7 @@ def get_device_info(args, failures):
v['ro.build.fingerprint'] for v in device_info if not v['denylisted']]

def unique_build_details(index):
return sorted(list(set([v.split(':')[index] for v in details])))
return sorted(list({v.split(':')[index] for v in details}))

parsed_details = {
'device_names': unique_build_details(0),
Expand Down
6 changes: 4 additions & 2 deletions testing/scripts/metrics_python_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 9,10 @@
import os
import sys


import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


def main_run(args):
Expand Down
8 changes: 6 additions & 2 deletions testing/scripts/run_cast_core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 19,13 @@
"""

import json
import os
import sys

import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


class CastCoreIntegrationTestAdapter(common.BaseIsolatedScriptArgsAdapter):
Expand All @@ -47,4 51,4 @@ def main_compile_targets(args):
'compile_targets': main_compile_targets,
}
sys.exit(common.run_script(sys.argv[1:], funcs))
sys.exit(main())
sys.exit(main())
5 changes: 4 additions & 1 deletion testing/scripts/run_chromedriver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,10 @@
import tempfile
import traceback

import common
# Add src/testing/ into sys.path for importing common without pylint errors.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
from scripts import common


class ChromeDriverAdapter(common.BaseIsolatedScriptArgsAdapter):
Expand Down
8 changes: 4 additions & 4 deletions testing/scripts/run_devtools_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 21,11 @@
import sys


import common

# Add src/testing/ into sys.path for importing xvfb.
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
# Add src/testing/ into sys.path for importing xvfb and common.
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)))
import xvfb
from scripts import common


def main():
Expand Down
Loading

0 comments on commit 3fade1f

Please sign in to comment.