mirror of
https://github.com/servo/servo.git
synced 2025-07-24 07:40:27 +01:00
Run py-modernize against tests/jquery/run_jquery.py
Attempt to make it py3 compatible
This commit is contained in:
parent
2d055cbf6b
commit
cc18718152
1 changed files with 16 additions and 12 deletions
|
@ -4,15 +4,18 @@
|
||||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import BaseHTTPServer
|
import six.moves.BaseHTTPServer
|
||||||
import SimpleHTTPServer
|
import six.moves.SimpleHTTPServer
|
||||||
import SocketServer
|
import six.moves.socketserver
|
||||||
import threading
|
import threading
|
||||||
import urlparse
|
import six.moves.urllib.parse
|
||||||
|
import six
|
||||||
|
|
||||||
# List of jQuery modules that will be tested.
|
# List of jQuery modules that will be tested.
|
||||||
# TODO(gw): Disabled most of them as something has been
|
# TODO(gw): Disabled most of them as something has been
|
||||||
|
@ -46,7 +49,7 @@ JQUERY_MODULES = [
|
||||||
TEST_SERVER_PORT = 8192
|
TEST_SERVER_PORT = 8192
|
||||||
|
|
||||||
# A regex for matching console.log output lines from the test runner.
|
# A regex for matching console.log output lines from the test runner.
|
||||||
REGEX_PATTERN = "^\[jQuery test\] \[([0-9]+)/([0-9]+)/([0-9]+)] (.*)"
|
REGEX_PATTERN = r"^\[jQuery test\] \[([0-9]+)/([0-9]+)/([0-9]+)] (.*)"
|
||||||
|
|
||||||
|
|
||||||
# The result of a single test group.
|
# The result of a single test group.
|
||||||
|
@ -103,7 +106,7 @@ def run_servo(servo_exe, module):
|
||||||
break
|
break
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
try:
|
try:
|
||||||
name, test_result = parse_line_to_result(line)
|
name, test_result = parse_line_to_result(line.decode('utf-8'))
|
||||||
yield name, test_result
|
yield name, test_result
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
@ -124,7 +127,7 @@ def read_existing_results(module):
|
||||||
# Write a set of results to file
|
# Write a set of results to file
|
||||||
def write_results(module, results):
|
def write_results(module, results):
|
||||||
with open(module_filename(module), 'w') as file:
|
with open(module_filename(module), 'w') as file:
|
||||||
for result in test_results.itervalues():
|
for result in six.itervalues(test_results):
|
||||||
file.write(result.text + '\n')
|
file.write(result.text + '\n')
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,24 +138,24 @@ def print_usage():
|
||||||
|
|
||||||
# Run a simple HTTP server to serve up the jQuery test suite
|
# Run a simple HTTP server to serve up the jQuery test suite
|
||||||
def run_http_server():
|
def run_http_server():
|
||||||
class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
|
class ThreadingSimpleServer(six.moves.socketserver.ThreadingMixIn,
|
||||||
BaseHTTPServer.HTTPServer):
|
six.moves.BaseHTTPServer.HTTPServer):
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
|
|
||||||
class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
|
class RequestHandler(six.moves.SimpleHTTPServer.SimpleHTTPRequestHandler):
|
||||||
# TODO(gw): HACK copy the fixed version from python
|
# TODO(gw): HACK copy the fixed version from python
|
||||||
# main repo - due to https://bugs.python.org/issue23112
|
# main repo - due to https://bugs.python.org/issue23112
|
||||||
def send_head(self):
|
def send_head(self):
|
||||||
path = self.translate_path(self.path)
|
path = self.translate_path(self.path)
|
||||||
f = None
|
f = None
|
||||||
if os.path.isdir(path):
|
if os.path.isdir(path):
|
||||||
parts = urlparse.urlsplit(self.path)
|
parts = six.moves.urllib.parse.urlsplit(self.path)
|
||||||
if not parts.path.endswith('/'):
|
if not parts.path.endswith('/'):
|
||||||
# redirect browser - doing basically what apache does
|
# redirect browser - doing basically what apache does
|
||||||
self.send_response(301)
|
self.send_response(301)
|
||||||
new_parts = (parts[0], parts[1], parts[2] + '/',
|
new_parts = (parts[0], parts[1], parts[2] + '/',
|
||||||
parts[3], parts[4])
|
parts[3], parts[4])
|
||||||
new_url = urlparse.urlunsplit(new_parts)
|
new_url = six.moves.urllib.parse.urlunsplit(new_parts)
|
||||||
self.send_header("Location", new_url)
|
self.send_header("Location", new_url)
|
||||||
self.end_headers()
|
self.end_headers()
|
||||||
return None
|
return None
|
||||||
|
@ -251,6 +254,7 @@ if __name__ == '__main__':
|
||||||
print("\t{0} tests succeeded of {1} ({2:.2f}%)".format(individual_success,
|
print("\t{0} tests succeeded of {1} ({2:.2f}%)".format(individual_success,
|
||||||
individual_total,
|
individual_total,
|
||||||
100.0 * individual_success / individual_total))
|
100.0 * individual_success / individual_total))
|
||||||
|
|
||||||
if unexpected_count > 0:
|
if unexpected_count > 0:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif cmd == "update":
|
elif cmd == "update":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue