Migrate finch smoke test to python3
Bug: 1291047 Change-Id: Ic4c3dacada8047a6de3276657a02a4fe06de1e40 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3418459 Reviewed-by: Takuto Ikuta <tikuta@chromium.org> Reviewed-by: Stephen Martinis <martiniss@chromium.org> Reviewed-by: Dirk Pranke <dpranke@google.com> Commit-Queue: Arthur Wang <wuwang@chromium.org> Cr-Commit-Position: refs/heads/main@{#966564}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
33a7c455e2
commit
763ce26bf4
@@ -394,3 +394,10 @@ wheel: <
|
|||||||
platform: "linux_aarch64"
|
platform: "linux_aarch64"
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
|
|
||||||
|
# Used by:
|
||||||
|
# testing/script/run_variations_smoke_tests.py
|
||||||
|
wheel: <
|
||||||
|
name: "infra/python/wheels/selenium-py3"
|
||||||
|
version: "version:3.14.0"
|
||||||
|
>
|
||||||
|
@@ -9941,7 +9941,6 @@ if (is_chromeos_ash) {
|
|||||||
|
|
||||||
if (is_linux || is_mac || is_win) {
|
if (is_linux || is_mac || is_win) {
|
||||||
script_test("variations_smoke_tests") {
|
script_test("variations_smoke_tests") {
|
||||||
run_under_python2 = true
|
|
||||||
|
|
||||||
if (is_linux) {
|
if (is_linux) {
|
||||||
script = "//testing/xvfb.py"
|
script = "//testing/xvfb.py"
|
||||||
@@ -9960,8 +9959,8 @@ if (is_linux || is_mac || is_win) {
|
|||||||
]
|
]
|
||||||
|
|
||||||
data = [
|
data = [
|
||||||
|
"//.vpython3",
|
||||||
"//testing/scripts/run_variations_smoke_tests.py",
|
"//testing/scripts/run_variations_smoke_tests.py",
|
||||||
"//testing/scripts/variations_http_test_server.py",
|
|
||||||
"//testing/scripts/variations_seed_access_helper.py",
|
"//testing/scripts/variations_seed_access_helper.py",
|
||||||
"//testing/scripts/variations_smoke_test_data/",
|
"//testing/scripts/variations_smoke_test_data/",
|
||||||
"//testing/scripts/variations_smoke_test_data/http_server/",
|
"//testing/scripts/variations_smoke_test_data/http_server/",
|
||||||
|
@@ -33,10 +33,10 @@ def main(argv):
|
|||||||
'PRESUBMIT.py',
|
'PRESUBMIT.py',
|
||||||
'sizes_common.py',
|
'sizes_common.py',
|
||||||
'variations_seed_access_helper.py',
|
'variations_seed_access_helper.py',
|
||||||
'variations_http_test_server.py',
|
|
||||||
'wpt_android_lib.py',
|
'wpt_android_lib.py',
|
||||||
'wpt_common.py',
|
'wpt_common.py',
|
||||||
'wpt_common_unittest.py',
|
'wpt_common_unittest.py',
|
||||||
|
'run_variations_smoke_tests.py',
|
||||||
'run_performance_tests_unittest.py'):
|
'run_performance_tests_unittest.py'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env vpython
|
#!/usr/bin/env vpython3
|
||||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
# Copyright 2021 The Chromium Authors. All rights reserved.
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
# Use of this source code is governed by a BSD-style license that can be
|
||||||
# found in the LICENSE file.
|
# found in the LICENSE file.
|
||||||
@@ -7,6 +7,7 @@ when parsing a newly given variations seed.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import http
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
@@ -14,24 +15,17 @@ import shutil
|
|||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import six.moves.urllib.error
|
from functools import partial
|
||||||
|
from http.server import SimpleHTTPRequestHandler
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|
||||||
import common
|
import common
|
||||||
import six
|
|
||||||
import variations_seed_access_helper as seed_helper
|
import variations_seed_access_helper as seed_helper
|
||||||
from variations_http_test_server import HTTPServer
|
|
||||||
from variations_http_test_server import HTTPHandler
|
|
||||||
|
|
||||||
if six.PY3:
|
|
||||||
import http
|
|
||||||
|
|
||||||
_THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
_THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
_SRC_DIR = os.path.join(_THIS_DIR, os.path.pardir, os.path.pardir)
|
_SRC_DIR = os.path.join(_THIS_DIR, os.path.pardir, os.path.pardir)
|
||||||
_WEBDRIVER_PATH = os.path.join(_SRC_DIR, 'third_party', 'webdriver', 'pylib')
|
|
||||||
_VARIATIONS_TEST_DATA = 'variations_smoke_test_data'
|
_VARIATIONS_TEST_DATA = 'variations_smoke_test_data'
|
||||||
|
|
||||||
sys.path.insert(0, _WEBDRIVER_PATH)
|
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver import ChromeOptions
|
from selenium.webdriver import ChromeOptions
|
||||||
from selenium.common.exceptions import NoSuchElementException
|
from selenium.common.exceptions import NoSuchElementException
|
||||||
@@ -63,14 +57,10 @@ def _get_httpd():
|
|||||||
port = 8000
|
port = 8000
|
||||||
directory = os.path.join(_THIS_DIR, _VARIATIONS_TEST_DATA, "http_server")
|
directory = os.path.join(_THIS_DIR, _VARIATIONS_TEST_DATA, "http_server")
|
||||||
httpd = None
|
httpd = None
|
||||||
if six.PY3:
|
handler = partial(SimpleHTTPRequestHandler, directory=directory)
|
||||||
handler = partial(http.server.SimpleHTTPRequestHandler, directory=directory)
|
httpd = http.server.HTTPServer((hostname, port), handler)
|
||||||
httpd = http.server.HTTPServer((hostname, port), handler)
|
httpd.timeout = 0.5
|
||||||
httpd.timeout = 0.5
|
httpd.allow_reuse_address = True
|
||||||
httpd.allow_reuse_address = True
|
|
||||||
httpd.server_bind()
|
|
||||||
else:
|
|
||||||
httpd = HTTPServer(directory, (hostname, port))
|
|
||||||
return httpd
|
return httpd
|
||||||
|
|
||||||
|
|
||||||
@@ -246,11 +236,7 @@ def _run_tests(*args):
|
|||||||
|
|
||||||
shutil.rmtree(log_file, ignore_errors=True)
|
shutil.rmtree(log_file, ignore_errors=True)
|
||||||
if driver:
|
if driver:
|
||||||
try:
|
driver.quit()
|
||||||
driver.quit()
|
|
||||||
except six.moves.urllib.error.URLError:
|
|
||||||
# Ignore the error as ChromeDriver may have already exited.
|
|
||||||
pass
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -263,14 +249,10 @@ def _start_local_http_server():
|
|||||||
"""
|
"""
|
||||||
httpd = _get_httpd()
|
httpd = _get_httpd()
|
||||||
thread = None
|
thread = None
|
||||||
if six.PY3:
|
address = "http://{}:{}".format(httpd.server_name, httpd.server_port)
|
||||||
address = "http://{}:{}".format(httpd.server_name, httpd.server_port)
|
logging.info("%s is used as local http server.", address)
|
||||||
logging.info("%s is used as local http server.", address)
|
thread = Thread(target=httpd.serve_forever)
|
||||||
thread = Thread(target=httpd.serve_forever)
|
thread.setDaemon(True)
|
||||||
thread.setDaemon(True)
|
|
||||||
else:
|
|
||||||
thread = Thread(target=httpd.serve_forever)
|
|
||||||
thread.daemon = True
|
|
||||||
thread.start()
|
thread.start()
|
||||||
return httpd
|
return httpd
|
||||||
|
|
||||||
|
@@ -1,41 +0,0 @@
|
|||||||
# Copyright 2021 The Chromium Authors. All rights reserved.
|
|
||||||
# Use of this source code is governed by a BSD-style license that can be
|
|
||||||
# found in the LICENSE file.
|
|
||||||
"""A http server implementation based on SimpleHTTPServer or http.server and
|
|
||||||
serves content from a base_path.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
try:
|
|
||||||
# Python 2
|
|
||||||
from SimpleHTTPServer import SimpleHTTPRequestHandler
|
|
||||||
from BaseHTTPServer import HTTPServer as BaseHTTPServer
|
|
||||||
except ImportError:
|
|
||||||
# Python 3
|
|
||||||
from http.server import SimpleHTTPRequestHandler
|
|
||||||
from http.server import HTTPServer as BaseHTTPServer
|
|
||||||
|
|
||||||
class HTTPHandler(SimpleHTTPRequestHandler):
|
|
||||||
"""This handler allows to specify a bath_path. """
|
|
||||||
def translate_path(self, path):
|
|
||||||
"""Uses server.base_path to combine full path."""
|
|
||||||
path = SimpleHTTPRequestHandler.translate_path(self, path)
|
|
||||||
real_path = os.path.relpath(path, os.getcwd())
|
|
||||||
return os.path.join(self.server.base_path, real_path)
|
|
||||||
|
|
||||||
class HTTPServer(BaseHTTPServer):
|
|
||||||
"""The main server, which you couild override base_path."""
|
|
||||||
def __init__(self, base_path, server_address,
|
|
||||||
RequestHandlerClass=HTTPHandler):
|
|
||||||
self.base_path = base_path
|
|
||||||
self.stop = False
|
|
||||||
BaseHTTPServer.__init__(self, server_address, RequestHandlerClass)
|
|
||||||
|
|
||||||
#pylint: disable=unused-argument
|
|
||||||
def serve_forever(self, poll_interval=0.1):
|
|
||||||
self.stop = False
|
|
||||||
while not self.stop:
|
|
||||||
self.handle_request()
|
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
self.stop = True
|
|
Reference in New Issue
Block a user