From 8defc6c6da91e4b7d7a686b7bb67658d9a5ebe55 Mon Sep 17 00:00:00 2001 From: Joshua Hood Date: Tue, 26 Apr 2022 15:35:06 +0000 Subject: [PATCH] [CodeHealth] Migrate remainder of testing/ to Python3 compatible syntax 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 Commit-Queue: Joshua Hood Cr-Commit-Position: refs/heads/main@{#996200} --- testing/PRESUBMIT.py | 19 +++---------- testing/__init__.py | 0 testing/buildbot/PRESUBMIT_test.py | 6 ++++- testing/buildbot/__init__.py | 0 testing/chromoting/browser_tests_launcher.py | 2 +- testing/scripts/__init__.py | 0 testing/scripts/blink_lint_expectations.py | 6 +++-- testing/scripts/blink_python_tests.py | 6 +++-- testing/scripts/check_gn_headers.py | 6 +++-- testing/scripts/check_network_annotations.py | 6 +++-- testing/scripts/check_static_initializers.py | 5 +++- testing/scripts/checkbins.py | 7 +++-- testing/scripts/checkdeps.py | 5 +++- testing/scripts/checklicenses.py | 5 +++- testing/scripts/checkperms.py | 5 +++- testing/scripts/common.py | 7 +++-- testing/scripts/content_shell_crash_test.py | 8 +++--- testing/scripts/count_filtered_tests.py | 5 +++- testing/scripts/get_compile_targets.py | 11 ++++++-- .../scripts/gpu_integration_test_adapter.py | 9 ++++++- testing/scripts/grit_python_unittests.py | 5 +++- testing/scripts/headless_python_unittests.py | 8 +++--- testing/scripts/host_info.py | 7 +++-- testing/scripts/metrics_python_tests.py | 6 +++-- testing/scripts/run_android_wpt.py | 6 ++++- testing/scripts/run_android_wpt.pydeps | 1 + testing/scripts/run_cast_core_tests.py | 8 ++++-- testing/scripts/run_chromedriver_tests.py | 5 +++- testing/scripts/run_devtools_check.py | 8 +++--- .../scripts/run_finch_smoke_tests_android.py | 8 +++++- testing/scripts/run_flatbuffers_unittests.py | 11 +++++--- .../run_gpu_integration_test_as_googletest.py | 7 ++++- testing/scripts/run_isolated_script_test.py | 14 +++++----- .../scripts/run_isolated_script_test.pydeps | 1 + testing/scripts/run_performance_tests.py | 27 ++++++++++--------- ...dering_benchmark_with_gated_performance.py | 11 ++++++-- .../scripts/run_telemetry_as_googletest.py | 5 +++- testing/scripts/run_variations_smoke_tests.py | 8 +++--- testing/scripts/run_wpt_tests.py | 26 ++++++++++-------- testing/scripts/rust/rust_main_program.py | 2 +- testing/scripts/rust/test_filtering.py | 3 +-- .../skia_gold_infra/finch_skia_gold_utils.py | 1 - .../test_buildbucket_api_gpu_use_cases.py | 10 ++++--- .../test_traffic_annotation_auditor.py | 5 +++- testing/scripts/wpt_common.py | 7 ++++- testing/test_env.py | 13 +++++---- testing/test_env_test_script.py | 2 +- testing/test_env_unittest.py | 8 ++++-- .../unittest_utils.py | 4 +++ testing/variations/PRESUBMIT.py | 4 +-- testing/xvfb.py | 11 ++++---- testing/xvfb_unittest.py | 12 ++++++--- 52 files changed, 242 insertions(+), 130 deletions(-) create mode 100644 testing/__init__.py create mode 100644 testing/buildbot/__init__.py create mode 100644 testing/scripts/__init__.py diff --git a/testing/PRESUBMIT.py b/testing/PRESUBMIT.py index 61b4fc1888d40b..6a5524c7c28790 100644 --- a/testing/PRESUBMIT.py +++ b/testing/PRESUBMIT.py @@ -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, @@ -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 diff --git a/testing/__init__.py b/testing/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/testing/buildbot/PRESUBMIT_test.py b/testing/buildbot/PRESUBMIT_test.py index 0ef25a45d1028e..38e97fc99867b7 100755 --- a/testing/buildbot/PRESUBMIT_test.py +++ b/testing/buildbot/PRESUBMIT_test.py @@ -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: diff --git a/testing/buildbot/__init__.py b/testing/buildbot/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/testing/chromoting/browser_tests_launcher.py b/testing/chromoting/browser_tests_launcher.py index 6f0ba62f23325a..c0dd8490d4d2c4 100644 --- a/testing/chromoting/browser_tests_launcher.py +++ b/testing/chromoting/browser_tests_launcher.py @@ -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 diff --git a/testing/scripts/__init__.py b/testing/scripts/__init__.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/testing/scripts/blink_lint_expectations.py b/testing/scripts/blink_lint_expectations.py index bb26b917659a7a..c1f2ad940ca951 100755 --- a/testing/scripts/blink_lint_expectations.py +++ b/testing/scripts/blink_lint_expectations.py @@ -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): diff --git a/testing/scripts/blink_python_tests.py b/testing/scripts/blink_python_tests.py index c7f14e686a58e7..a9c854be85c323 100755 --- a/testing/scripts/blink_python_tests.py +++ b/testing/scripts/blink_python_tests.py @@ -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): diff --git a/testing/scripts/check_gn_headers.py b/testing/scripts/check_gn_headers.py index 6530ada7097947..ccf0ba216a94a2 100755 --- a/testing/scripts/check_gn_headers.py +++ b/testing/scripts/check_gn_headers.py @@ -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): diff --git a/testing/scripts/check_network_annotations.py b/testing/scripts/check_network_annotations.py index 6e2875d861552c..7d05b49ace5562 100755 --- a/testing/scripts/check_network_annotations.py +++ b/testing/scripts/check_network_annotations.py @@ -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): diff --git a/testing/scripts/check_static_initializers.py b/testing/scripts/check_static_initializers.py index 3afd112883b5f4..dc9b1d27451014 100755 --- a/testing/scripts/check_static_initializers.py +++ b/testing/scripts/check_static_initializers.py @@ -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 diff --git a/testing/scripts/checkbins.py b/testing/scripts/checkbins.py index f66c8b144bdc4f..af8208dc6ffb4a 100755 --- a/testing/scripts/checkbins.py +++ b/testing/scripts/checkbins.py @@ -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 diff --git a/testing/scripts/checkdeps.py b/testing/scripts/checkdeps.py index e772ae874902c8..9c49d8242302ce 100755 --- a/testing/scripts/checkdeps.py +++ b/testing/scripts/checkdeps.py @@ -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): diff --git a/testing/scripts/checklicenses.py b/testing/scripts/checklicenses.py index 43342d02546604..3a51fcf6f02434 100755 --- a/testing/scripts/checklicenses.py +++ b/testing/scripts/checklicenses.py @@ -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): diff --git a/testing/scripts/checkperms.py b/testing/scripts/checkperms.py index 8adb0256c880df..e635aa12735276 100755 --- a/testing/scripts/checkperms.py +++ b/testing/scripts/checkperms.py @@ -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): diff --git a/testing/scripts/common.py b/testing/scripts/common.py index 1c31066d7a4d57..d57595cb058de5 100644 --- a/testing/scripts/common.py +++ b/testing/scripts/common.py @@ -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 @@ -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.""" @@ -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() diff --git a/testing/scripts/content_shell_crash_test.py b/testing/scripts/content_shell_crash_test.py index fe3515a7f7399b..60f76a75868970 100755 --- a/testing/scripts/content_shell_crash_test.py +++ b/testing/scripts/content_shell_crash_test.py @@ -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. diff --git a/testing/scripts/count_filtered_tests.py b/testing/scripts/count_filtered_tests.py index 97bb8f54172d72..588c87f9f9de28 100644 --- a/testing/scripts/count_filtered_tests.py +++ b/testing/scripts/count_filtered_tests.py @@ -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): diff --git a/testing/scripts/get_compile_targets.py b/testing/scripts/get_compile_targets.py index 3772d50a5616b8..75e15dc9d75107 100755 --- a/testing/scripts/get_compile_targets.py +++ b/testing/scripts/get_compile_targets.py @@ -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): @@ -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) diff --git a/testing/scripts/gpu_integration_test_adapter.py b/testing/scripts/gpu_integration_test_adapter.py index 8c12571d7253a9..6aae983e9ff96c 100644 --- a/testing/scripts/gpu_integration_test_adapter.py +++ b/testing/scripts/gpu_integration_test_adapter.py @@ -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): diff --git a/testing/scripts/grit_python_unittests.py b/testing/scripts/grit_python_unittests.py index 532e4b1b0c5275..9a2218e5e26508 100755 --- a/testing/scripts/grit_python_unittests.py +++ b/testing/scripts/grit_python_unittests.py @@ -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): diff --git a/testing/scripts/headless_python_unittests.py b/testing/scripts/headless_python_unittests.py index 881cff4a6ebb30..4e32907528efeb 100755 --- a/testing/scripts/headless_python_unittests.py +++ b/testing/scripts/headless_python_unittests.py @@ -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): @@ -16,7 +18,7 @@ def main_run(args): 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') diff --git a/testing/scripts/host_info.py b/testing/scripts/host_info.py index 63e3b9ba308cbf..86c85148c9b5e9 100755 --- a/testing/scripts/host_info.py +++ b/testing/scripts/host_info.py @@ -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(): @@ -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), diff --git a/testing/scripts/metrics_python_tests.py b/testing/scripts/metrics_python_tests.py index 70770f41b56e2f..27464302338915 100755 --- a/testing/scripts/metrics_python_tests.py +++ b/testing/scripts/metrics_python_tests.py @@ -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): diff --git a/testing/scripts/run_android_wpt.py b/testing/scripts/run_android_wpt.py index db183b2a3fcd43..0417a5775d0664 100755 --- a/testing/scripts/run_android_wpt.py +++ b/testing/scripts/run_android_wpt.py @@ -26,12 +26,16 @@ # run_wpt_tests.py script. import json +import os import sys -import common from run_wpt_tests import WPTAdapter +# 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 # This is not really a "script test" so does not need to manually add # any additional compile targets. diff --git a/testing/scripts/run_android_wpt.pydeps b/testing/scripts/run_android_wpt.pydeps index ac6fdf58357010..cba4c8d81774f9 100644 --- a/testing/scripts/run_android_wpt.pydeps +++ b/testing/scripts/run_android_wpt.pydeps @@ -20,6 +20,7 @@ //build/util/lib/results/__init__.py //build/util/lib/results/result_sink.py //build/util/lib/results/result_types.py +//testing/scripts/__init__.py //testing/scripts/common.py //testing/scripts/run_android_wpt.py //testing/scripts/run_wpt_tests.py diff --git a/testing/scripts/run_cast_core_tests.py b/testing/scripts/run_cast_core_tests.py index f94e106469dcd3..7d5e9e9aedfe77 100755 --- a/testing/scripts/run_cast_core_tests.py +++ b/testing/scripts/run_cast_core_tests.py @@ -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): @@ -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()) \ No newline at end of file + sys.exit(main()) diff --git a/testing/scripts/run_chromedriver_tests.py b/testing/scripts/run_chromedriver_tests.py index b1f67ce54f6c57..203ae32d482ece 100755 --- a/testing/scripts/run_chromedriver_tests.py +++ b/testing/scripts/run_chromedriver_tests.py @@ -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): diff --git a/testing/scripts/run_devtools_check.py b/testing/scripts/run_devtools_check.py index 104f5f72b2bdad..9f9be6315b394d 100755 --- a/testing/scripts/run_devtools_check.py +++ b/testing/scripts/run_devtools_check.py @@ -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(): diff --git a/testing/scripts/run_finch_smoke_tests_android.py b/testing/scripts/run_finch_smoke_tests_android.py index e3d912203cc7c8..cd12b7e1f547fe 100755 --- a/testing/scripts/run_finch_smoke_tests_android.py +++ b/testing/scripts/run_finch_smoke_tests_android.py @@ -19,6 +19,7 @@ SRC_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) +PAR_DIR = os.path.join(SRC_DIR, 'testing') OUT_DIR = os.path.join(SRC_DIR, 'out', 'Release') BLINK_TOOLS = os.path.join( SRC_DIR, 'third_party', 'blink', 'tools') @@ -46,10 +47,11 @@ if WEBVIEW_VARIATIONS_PROTO not in sys.path: sys.path.append(WEBVIEW_VARIATIONS_PROTO) +sys.path.append(PAR_DIR) + if 'compile_targets' not in sys.argv: import aw_variations_seed_pb2 -import common import devil_chromium import wpt_common @@ -66,6 +68,7 @@ from devil.utils import logging_common from pylib.local.emulator import avd from py_utils.tempfile_ext import NamedTemporaryDirectory +from scripts import common from skia_gold_infra.finch_skia_gold_properties import FinchSkiaGoldProperties from skia_gold_infra import finch_skia_gold_session_manager from skia_gold_infra import finch_skia_gold_utils @@ -82,6 +85,8 @@ logger.setLevel(logging.INFO) TEST_CASES = {} +# pylint: disable=super-with-arguments + class FinchTestCase(wpt_common.BaseWptScriptAdapter): @@ -95,6 +100,7 @@ def __init__(self, device): self.browser_activity_name = (self.options.browser_activity_name or self.default_browser_activity_name) self.log_mon = None + self.layout_test_results_subdir = None self.test_specific_browser_args = [] if self.options.webview_provider_apk: self.webview_provider_package_name = ( diff --git a/testing/scripts/run_flatbuffers_unittests.py b/testing/scripts/run_flatbuffers_unittests.py index c9b8fde95e9cdf..daea0f523846ab 100755 --- a/testing/scripts/run_flatbuffers_unittests.py +++ b/testing/scripts/run_flatbuffers_unittests.py @@ -20,11 +20,14 @@ import os import sys -import common - -# Add src/testing/ into sys.path for importing xvfb and test_env. -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 + +# pylint: disable=super-with-arguments + def main(): parser = argparse.ArgumentParser() diff --git a/testing/scripts/run_gpu_integration_test_as_googletest.py b/testing/scripts/run_gpu_integration_test_as_googletest.py index dc5e12846589db..3456a7e40a6479 100755 --- a/testing/scripts/run_gpu_integration_test_as_googletest.py +++ b/testing/scripts/run_gpu_integration_test_as_googletest.py @@ -19,11 +19,16 @@ """ import json +import os import sys -import common import gpu_integration_test_adapter +# 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(): adapter = gpu_integration_test_adapter.GpuIntegrationTestAdapater() diff --git a/testing/scripts/run_isolated_script_test.py b/testing/scripts/run_isolated_script_test.py index fed588325230e0..0e963d639006bd 100755 --- a/testing/scripts/run_isolated_script_test.py +++ b/testing/scripts/run_isolated_script_test.py @@ -26,7 +26,11 @@ import tempfile -import common +# 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 # Some harnesses understand the --isolated-script-test arguments @@ -52,10 +56,9 @@ 'test_suite_all.py', # //tools/grit:grit_python_unittests } -class IsolatedScriptTestAdapter(common.BaseIsolatedScriptArgsAdapter): - def __init__(self): - super(IsolatedScriptTestAdapter, self).__init__() +# pylint: disable=super-with-arguments +class IsolatedScriptTestAdapter(common.BaseIsolatedScriptArgsAdapter): def generate_sharding_args(self, total_shards, shard_index): # This script only uses environment variable for sharding. del total_shards, shard_index # unused @@ -118,9 +121,6 @@ def select_python_executable(self): return 'vpython3.bat' if sys.platform == 'win32' else 'vpython3' return super(TypUnittestAdapter, self).select_python_executable() - def run_test(self): - return super(TypUnittestAdapter, self).run_test() - def main(): if any(r in sys.argv[1] for r in KNOWN_ISOLATED_SCRIPT_TEST_RUNNERS): diff --git a/testing/scripts/run_isolated_script_test.pydeps b/testing/scripts/run_isolated_script_test.pydeps index bc8ff58121c833..df35f829bd6419 100644 --- a/testing/scripts/run_isolated_script_test.pydeps +++ b/testing/scripts/run_isolated_script_test.pydeps @@ -4,6 +4,7 @@ //build/util/lib/results/__init__.py //build/util/lib/results/result_sink.py //build/util/lib/results/result_types.py +//testing/scripts/__init__.py //testing/scripts/common.py //testing/scripts/run_isolated_script_test.py //testing/test_env.py diff --git a/testing/scripts/run_performance_tests.py b/testing/scripts/run_performance_tests.py index b687be82db85a2..a46efbe54aa53b 100755 --- a/testing/scripts/run_performance_tests.py +++ b/testing/scripts/run_performance_tests.py @@ -48,11 +48,11 @@ import traceback import six -import common from collections import OrderedDict CHROMIUM_SRC_DIR = os.path.abspath( - os.path.join(os.path.dirname(__file__), '..', '..')) + os.path.join(os.path.dirname(__file__), + os.path.pardir, os.path.pardir)) PERF_DIR = os.path.join(CHROMIUM_SRC_DIR, 'tools', 'perf') sys.path.append(PERF_DIR) @@ -63,19 +63,21 @@ sys.path.append(PERF_CORE_DIR) import results_merger -# Add src/testing/ into sys.path for importing xvfb and test_env. -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +# Add src/testing/ into sys.path for importing xvfb, test_env, and common. +sys.path.append( + os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) import xvfb import test_env +from scripts import common # Unfortunately we need to copy these variables from ../test_env.py. # Importing it and using its get_sandbox_env breaks test runs on Linux # (it seems to unset DISPLAY). CHROME_SANDBOX_ENV = 'CHROME_DEVEL_SANDBOX' CHROME_SANDBOX_PATH = '/opt/chromium/chrome_sandbox' -SHARD_MAPS_DIRECTORY = os.path.join( - os.path.dirname(__file__), '..', '..', 'tools', 'perf', 'core', - 'shard_maps') +SHARD_MAPS_DIRECTORY = os.path.abspath( + os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, + 'tools', 'perf', 'core', 'shard_maps')) # See https://crbug.com/923564. # We want to switch over to using histograms for everything, but converting from @@ -106,6 +108,8 @@ 'xr.vr.common_perftests', ] +# pylint: disable=useless-object-inheritance + class OutputFilePaths(object): """Provide paths to where results outputs should be written. @@ -188,8 +192,7 @@ def _get_executable(self): executable = str(self.executable_name) if IsWindows(): return r'.\%s.exe' % executable - else: - return './%s' % executable + return './%s' % executable def _get_additional_flags(self): return self._additional_flags @@ -246,7 +249,7 @@ def write_simple_test_results(return_code, output_filepath, benchmark_name): benchmark_name: { 'expected': 'PASS', 'actual': 'FAIL' if return_code else 'PASS', - 'is_unexpected': True if return_code else False, + 'is_unexpected': bool(return_code), }, }, 'interrupted': False, @@ -353,9 +356,9 @@ def execute_gtest_perf_test(command_generator, output_paths, use_xvfb=False, if os.path.exists(output_paths.perf_results): if command_generator.executable_name in GTEST_CONVERSION_WHITELIST: with path_util.SysPath(path_util.GetTracingDir()): - # pylint: disable=no-name-in-module + # pylint: disable=no-name-in-module,import-outside-toplevel from tracing.value import gtest_json_converter - # pylint: enable=no-name-in-module + # pylint: enable=no-name-in-module,import-outside-toplevel gtest_json_converter.ConvertGtestJsonFile(output_paths.perf_results) else: print('ERROR: gtest perf test %s did not generate perf output' % diff --git a/testing/scripts/run_rendering_benchmark_with_gated_performance.py b/testing/scripts/run_rendering_benchmark_with_gated_performance.py index 1011ac3ae43c45..39537a0b482f17 100755 --- a/testing/scripts/run_rendering_benchmark_with_gated_performance.py +++ b/testing/scripts/run_rendering_benchmark_with_gated_performance.py @@ -26,9 +26,13 @@ import numpy as np -import common import run_performance_tests +# 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 + # AVG_ERROR_MARGIN determines how much more the value of frame times can be # compared to the recorded value (multiplier of upper limit). AVG_ERROR_MARGIN = 1.1 @@ -40,6 +44,9 @@ METRIC_NAME = 'frame_times' +# pylint: disable=useless-object-inheritance + + class ResultRecorder(object): def __init__(self): self.fails = 0 @@ -152,7 +159,7 @@ def __init__(self, initialization_for_tests=False): # least by 10 [AVG_ERROR_MARGIN] percent of upper limit, that would be # considered a failure. crbug.com/953895 with open( - os.path.join(os.path.dirname(__file__), + os.path.join(os.path.dirname(os.path.abspath(__file__)), 'representative_perf_test_data', 'representatives_frame_times_upper_limit.json') ) as bound_data: diff --git a/testing/scripts/run_telemetry_as_googletest.py b/testing/scripts/run_telemetry_as_googletest.py index e05f7331c2a8d9..b67063bb52b78e 100755 --- a/testing/scripts/run_telemetry_as_googletest.py +++ b/testing/scripts/run_telemetry_as_googletest.py @@ -23,7 +23,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 class TelemetryUnittestAdapter(common.BaseIsolatedScriptArgsAdapter): diff --git a/testing/scripts/run_variations_smoke_tests.py b/testing/scripts/run_variations_smoke_tests.py index b681e54a0cb966..1bba02f2d5d6a9 100755 --- a/testing/scripts/run_variations_smoke_tests.py +++ b/testing/scripts/run_variations_smoke_tests.py @@ -21,12 +21,12 @@ from skia_gold_infra.finch_skia_gold_properties import FinchSkiaGoldProperties from skia_gold_infra import finch_skia_gold_utils -import common import variations_seed_access_helper as seed_helper _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) _VARIATIONS_TEST_DATA = 'variations_smoke_test_data' +from . import common from selenium import webdriver from selenium.webdriver import ChromeOptions from selenium.common.exceptions import NoSuchElementException @@ -84,7 +84,7 @@ def _get_platform(): 'Windows (win32 or cygwin) are supported' % sys.platform) -def _find_chrome_binary(): +def _find_chrome_binary(): #pylint: disable=inconsistent-return-statements """Finds and returns the relative path to the Chrome binary. This function assumes that the CWD is the build directory. @@ -95,11 +95,11 @@ def _find_chrome_binary(): platform = _get_platform() if platform == 'linux': return os.path.join('.', 'chrome') - elif platform == 'mac': + if platform == 'mac': chrome_name = 'Google Chrome' return os.path.join('.', chrome_name + '.app', 'Contents', 'MacOS', chrome_name) - elif platform == 'win': + if platform == 'win': return os.path.join('.', 'chrome.exe') diff --git a/testing/scripts/run_wpt_tests.py b/testing/scripts/run_wpt_tests.py index d592d83f07c083..2e7c0fff43cbf9 100755 --- a/testing/scripts/run_wpt_tests.py +++ b/testing/scripts/run_wpt_tests.py @@ -12,9 +12,13 @@ import os import sys -import common import wpt_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 + logger = logging.getLogger(__name__) SRC_DIR = os.path.abspath( @@ -54,6 +58,7 @@ _ANDROID_ENABLED = False +# pylint: disable=super-with-arguments def _make_pass_through_action(dest, map_arg=lambda arg: arg): class PassThroughAction(argparse.Action): def __init__(self, option_strings, dest, nargs=None, **kwargs): @@ -174,7 +179,7 @@ def _maybe_build_metadata(self): def log_level(self): if self.options.verbose >= 2: return logging.DEBUG - elif self.options.verbose >= 1: + if self.options.verbose >= 1: return logging.INFO return logging.WARNING @@ -431,7 +436,7 @@ def test_env(self): def wpt_args(self): """list[str]: Arguments to add to a 'wpt run' command.""" args = [] - version = self.get_version() + version = self.get_version() # pylint: disable=assignment-from-none if version: args.append('--browser-version=%s' % version) webdriver = self.webdriver_binary @@ -664,7 +669,7 @@ def get_browser_package_name(self): self).get_browser_package_name() if package_name: return package_name - elif self._options.shell_apk: + if self._options.shell_apk: with contextlib.suppress(apk_helper.ApkHelperError): return apk_helper.GetPackageName(self._options.shell_apk) return None @@ -708,12 +713,11 @@ def _install_webview(self, device): return webview_app.UseWebViewProvider( device, self._options.webview_provider) - else: - assert self._options.release_channel, 'no webview install method' - return _install_webview_from_release( - device, - self._options.release_channel, - self._python_executable) + assert self._options.release_channel, 'no webview install method' + return _install_webview_from_release( + device, + self._options.release_channel, + self._python_executable) def _validate_options(self): super(WebView, self)._validate_options() @@ -756,7 +760,7 @@ def get_browser_package_name(self): package_name = super(ChromeAndroid, self).get_browser_package_name() if package_name: return package_name - elif self._options.apk: + if self._options.apk: with contextlib.suppress(apk_helper.ApkHelperError): return apk_helper.GetPackageName(self._options.apk[0]) return None diff --git a/testing/scripts/rust/rust_main_program.py b/testing/scripts/rust/rust_main_program.py index 080dd2b9b56ec6..a1f95202514b1d 100644 --- a/testing/scripts/rust/rust_main_program.py +++ b/testing/scripts/rust/rust_main_program.py @@ -11,7 +11,7 @@ import subprocess import sys -sys.path.append(os.path.dirname(__file__)) +sys.path.append(os.path.dirname(os.path.abspath(__file__))) import exe_util import main_program import test_results diff --git a/testing/scripts/rust/test_filtering.py b/testing/scripts/rust/test_filtering.py index a386dd01f37553..bc9c7eea423ff1 100644 --- a/testing/scripts/rust/test_filtering.py +++ b/testing/scripts/rust/test_filtering.py @@ -56,8 +56,7 @@ def is_match(self, test_name): """ if self._is_prefix_match: return test_name.startswith(self._filter_text) - else: - return test_name == self._filter_text + return test_name == self._filter_text def is_exclusion_filter(self): """Rreturns whether this filter excludes (rather than includes) matching diff --git a/testing/scripts/skia_gold_infra/finch_skia_gold_utils.py b/testing/scripts/skia_gold_infra/finch_skia_gold_utils.py index a6784bfb69f010..8d6d3d364606e6 100644 --- a/testing/scripts/skia_gold_infra/finch_skia_gold_utils.py +++ b/testing/scripts/skia_gold_infra/finch_skia_gold_utils.py @@ -134,4 +134,3 @@ def log_skia_gold_status_code(skia_gold_session, image_name, status, error): 'Given unhandled SkiaGoldSession StatusCode %s with error %s', status, error) return triage_link - diff --git a/testing/scripts/test_buildbucket_api_gpu_use_cases.py b/testing/scripts/test_buildbucket_api_gpu_use_cases.py index af2b7f8ab5e78f..b4652a6cf48715 100755 --- a/testing/scripts/test_buildbucket_api_gpu_use_cases.py +++ b/testing/scripts/test_buildbucket_api_gpu_use_cases.py @@ -10,11 +10,15 @@ 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 # Add src/content/test/gpu into sys.path for importing common. -sys.path.append(os.path.join(os.path.dirname(__file__), - '..', '..', 'content', 'test', 'gpu')) +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), + os.path.pardir, os.path.pardir, 'content', + 'test', 'gpu'))) import gather_power_measurement_results import gather_swarming_json_results diff --git a/testing/scripts/test_traffic_annotation_auditor.py b/testing/scripts/test_traffic_annotation_auditor.py index 01f6399eac51ff..bcd0fb1a5e6870 100755 --- a/testing/scripts/test_traffic_annotation_auditor.py +++ b/testing/scripts/test_traffic_annotation_auditor.py @@ -15,7 +15,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 WINDOWS_SHEET_CONFIG = { "spreadsheet_id": "1TmBr9jnf1-hrjntiVBzT9EtkINGrtoBYFMWad2MBeaY", diff --git a/testing/scripts/wpt_common.py b/testing/scripts/wpt_common.py index 4a8634574bca56..33cb0c3f7f966d 100644 --- a/testing/scripts/wpt_common.py +++ b/testing/scripts/wpt_common.py @@ -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 BLINK_TOOLS_DIR = os.path.join(common.SRC_DIR, 'third_party', 'blink', 'tools') CATAPULT_DIR = os.path.join(common.SRC_DIR, 'third_party', 'catapult') @@ -30,6 +33,7 @@ logger = logging.getLogger(__name__) +# pylint: disable=super-with-arguments class BaseWptScriptAdapter(common.BaseIsolatedScriptArgsAdapter): """The base class for script adapters that use wptrunner to execute web platform tests. This contains any code shared between these scripts, such @@ -210,6 +214,7 @@ def generate_test_filter_args(self, test_filter_str): def generate_test_repeat_args(self, repeat_count): return ['--repeat=%d' % repeat_count] + # pylint: disable=unused-argument def generate_test_launcher_retry_limit_args(self, retry_limit): # TODO(crbug/1306222): wptrunner currently cannot rerun individual # failed tests, so this flag is accepted but not used. diff --git a/testing/test_env.py b/testing/test_env.py index fa8df4cdb3608d..43083fce5e084a 100755 --- a/testing/test_env.py +++ b/testing/test_env.py @@ -289,13 +289,15 @@ def _sig_handler(sig, _): if p.poll() is not None: continue # SIGBREAK is defined only for win32. + # pylint: disable=no-member if sys.platform == 'win32' and sig == signal.SIGBREAK: p.send_signal(signal.CTRL_BREAK_EVENT) else: print("Forwarding signal(%d) to process %d" % (sig, p.pid)) p.send_signal(sig) + # pylint: enable=no-member if sys.platform == 'win32': - signal.signal(signal.SIGBREAK, _sig_handler) + signal.signal(signal.SIGBREAK, _sig_handler) # pylint: disable=no-member else: signal.signal(signal.SIGTERM, _sig_handler) signal.signal(signal.SIGINT, _sig_handler) @@ -349,11 +351,13 @@ def run_executable(cmd, env, stdoutfile=None): if '--coverage-continuous-mode=1' in cmd: extra_env.update(get_coverage_continuous_mode_env(env)) + # pylint: disable=import-outside-toplevel if '--skip-set-lpac-acls=1' not in cmd and sys.platform == 'win32': sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'scripts')) - import common + from scripts import common common.set_lpac_acls(ROOT_DIR, is_test_script=True) + # pylint: enable=import-outside-toplevel cmd = trim_cmd(cmd) @@ -379,7 +383,7 @@ def run_executable(cmd, env, stdoutfile=None): if stdoutfile: # Write to stdoutfile and poll to produce terminal output. return run_command_with_output(cmd, env=env, stdoutfile=stdoutfile) - elif use_symbolization_script: + if use_symbolization_script: # See above comment regarding offline symbolization. # Need to pipe to the symbolizer script. p1 = _popen(cmd, env=env, stdout=subprocess.PIPE, @@ -394,8 +398,7 @@ def run_executable(cmd, env, stdoutfile=None): # Also feed the out-of-band JSON output to the symbolizer script. symbolize_snippets_in_json(cmd, env) return p1.returncode - else: - return run_command(cmd, env=env, log=False) + return run_command(cmd, env=env, log=False) except OSError: print('Failed to start %s' % cmd, file=sys.stderr) raise diff --git a/testing/test_env_test_script.py b/testing/test_env_test_script.py index 4957ee656d5760..e31814109ca611 100755 --- a/testing/test_env_test_script.py +++ b/testing/test_env_test_script.py @@ -19,5 +19,5 @@ def print_signal(sig, *_args): signal.signal(signal.SIGTERM, print_signal) signal.signal(signal.SIGINT, print_signal) if sys.platform == 'win32': - signal.signal(signal.SIGBREAK, print_signal) + signal.signal(signal.SIGBREAK, print_signal) # pylint: disable=no-member time.sleep(2) # gives process time to receive signal. diff --git a/testing/test_env_unittest.py b/testing/test_env_unittest.py index 707c65e9fdffae..8ec6194d39797b 100755 --- a/testing/test_env_unittest.py +++ b/testing/test_env_unittest.py @@ -20,6 +20,8 @@ HERE = os.path.dirname(os.path.abspath(__file__)) TEST_SCRIPT = os.path.join(HERE, 'test_env_user_script.py') +# pylint: disable=super-with-arguments + def launch_process_windows(args): # The `universal_newlines` option is equivalent to `text` in Python 3. @@ -42,11 +44,13 @@ def launch_process_nonwindows(args): universal_newlines=True) +# pylint: disable=inconsistent-return-statements def read_subprocess_message(proc, starts_with): """Finds the value after first line prefix condition.""" for line in proc.stdout: if line.startswith(starts_with): return line.rstrip().replace(starts_with, '') +# pylint: enable=inconsistent-return-statements def send_and_wait(proc, sig, sleep_time=0.3): @@ -65,9 +69,9 @@ def setUp(self): def test_send_ctrl_break_event(self): proc = launch_process_windows([]) - send_and_wait(proc, signal.CTRL_BREAK_EVENT) + send_and_wait(proc, signal.CTRL_BREAK_EVENT) # pylint: disable=no-member sig = read_subprocess_message(proc, 'Signal :') - self.assertEqual(sig, str(int(signal.SIGBREAK))) + self.assertEqual(sig, str(int(signal.SIGBREAK))) # pylint: disable=no-member class SignalingNonWindowsTest(unittest.TestCase): diff --git a/testing/unexpected_passes_common/unittest_utils.py b/testing/unexpected_passes_common/unittest_utils.py index 2df2f251a50612..bfc3b4050b2d61 100644 --- a/testing/unexpected_passes_common/unittest_utils.py +++ b/testing/unexpected_passes_common/unittest_utils.py @@ -141,11 +141,15 @@ def terminate(self): class GenericBuilders(builders.Builders): + #pylint: disable=useless-super-delegation def __init__(self, include_internal_builders=False): super(GenericBuilders, self).__init__(include_internal_builders) + #pylint: enable=useless-super-delegation + #pylint: disable=unused-argument def _BuilderRunsTestOfInterest(self, test_map, suite): return True + #pylint: enable=unused-argument def GetIsolateNames(self): return {} diff --git a/testing/variations/PRESUBMIT.py b/testing/variations/PRESUBMIT.py index e854e16258a780..fe5348372d13d5 100644 --- a/testing/variations/PRESUBMIT.py +++ b/testing/variations/PRESUBMIT.py @@ -257,10 +257,10 @@ def CommonChecks(input_api, output_api): json_data, f.AbsoluteLocalPath(), output_api.PresubmitError) - if len(result): + if result: return result result = CheckPretty(contents, f.LocalPath(), output_api.PresubmitError) - if len(result): + if result: return result except ValueError: return [ diff --git a/testing/xvfb.py b/testing/xvfb.py index c1f5f7655968dd..a301e55a049f44 100755 --- a/testing/xvfb.py +++ b/testing/xvfb.py @@ -23,15 +23,15 @@ import test_env +# pylint: disable=useless-object-inheritance + class _XvfbProcessError(Exception): """Exception raised when Xvfb cannot start.""" - pass class _WestonProcessError(Exception): """Exception raised when Weston cannot start.""" - pass def kill(proc, name, timeout_in_seconds=10): @@ -54,7 +54,7 @@ def kill(proc, name, timeout_in_seconds=10): file=sys.stderr) -def launch_dbus(env): +def launch_dbus(env): # pylint: disable=inconsistent-return-statements """Starts a DBus session. Works around a bug in GLib where it performs operations which aren't @@ -136,10 +136,9 @@ def run_executable( if sys.platform.startswith('linux') and use_xvfb: return _run_with_xvfb(cmd, env, stdoutfile, use_openbox, use_xcompmgr) - elif use_weston: + if use_weston: return _run_with_weston(cmd, env, stdoutfile) - else: - return test_env.run_executable(cmd, env, stdoutfile) + return test_env.run_executable(cmd, env, stdoutfile) def _run_with_xvfb(cmd, env, stdoutfile, use_openbox, use_xcompmgr): diff --git a/testing/xvfb_unittest.py b/testing/xvfb_unittest.py index f28b6d2316bd2f..47b78f8705a0dd 100755 --- a/testing/xvfb_unittest.py +++ b/testing/xvfb_unittest.py @@ -16,6 +16,8 @@ import time import unittest +# pylint: disable=super-with-arguments + TEST_FILE = __file__.replace('.pyc', '.py') XVFB = TEST_FILE.replace('_unittest', '') @@ -29,11 +31,13 @@ def launch_process(args): stderr=subprocess.STDOUT, env=os.environ.copy()) +# pylint: disable=inconsistent-return-statements def read_subprocess_message(proc, starts_with): """Finds the value after first line prefix condition.""" - for line in proc.stdout: + for line in proc.stdout.read().decode('utf-8').splitlines(True): if line.startswith(starts_with): return line.rstrip().replace(starts_with, '') +# pylint: enable=inconsistent-return-statements def send_signal(proc, sig, sleep_time=0.3): @@ -47,7 +51,7 @@ class XvfbLinuxTest(unittest.TestCase): def setUp(self): super(XvfbLinuxTest, self).setUp() - if sys.platform != 'linux2': + if sys.platform != 'linux': self.skipTest('linux only test') def test_no_xvfb_display(self): @@ -92,13 +96,13 @@ def test_send_sigint(self): proc = launch_process(['--sleep']) send_signal(proc, signal.SIGINT, 1) sig = read_subprocess_message(proc, 'Signal :') - self.assertEqual(sig, str(signal.SIGINT)) + self.assertEqual(int(sig), int(signal.SIGINT)) def test_send_sigterm(self): proc = launch_process(['--sleep']) send_signal(proc, signal.SIGTERM, 1) sig = read_subprocess_message(proc, 'Signal :') - self.assertEqual(sig, str(signal.SIGTERM)) + self.assertEqual(int(sig), int(signal.SIGTERM)) if __name__ == '__main__': unittest.main()