Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise tools scripts to be python3 compatible #4856

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def run_buildoption_test(options):
Check = collections.namedtuple('Check', ['enabled', 'runner', 'arg'])

def main(options):
util.setup_stdio()
checks = [
Check(options.check_signed_off, run_check, [settings.SIGNED_OFF_SCRIPT]
+ {'tolerant': ['--tolerant'], 'gh-actions': ['--gh-actions']}.get(options.check_signed_off, [])),
Expand Down
1 change: 1 addition & 0 deletions tools/runners/run-test-suite-test262.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def update_exclude_list(args):


def main(args):
util.setup_stdio()
return_code = prepare_test262_test_suite(args)
if return_code:
return return_code
Expand Down
1 change: 1 addition & 0 deletions tools/runners/run-test-suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def execute_test_command(test_cmd):


def main(args):
util.setup_stdio()
tests = get_tests(args.test_dir, args.test_list, args.skip_list)
total = len(tests)
if total == 0:
Expand Down
1 change: 1 addition & 0 deletions tools/runners/run-unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def get_unittests(path):


def main(args):
util.setup_stdio()
unittests = get_unittests(args.path)
total = len(unittests)
if total == 0:
Expand Down
3 changes: 3 additions & 0 deletions tools/runners/test262-harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
import threading
import multiprocessing

import util

#######################################################################
# based on _monkeyYaml.py
#######################################################################
Expand Down Expand Up @@ -917,6 +919,7 @@ def list_includes(self, tests):


def main():
util.setup_stdio()
code = 0
parser = build_options()
(options, args) = parser.parse_args()
Expand Down
12 changes: 12 additions & 0 deletions tools/runners/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.

from __future__ import print_function
import codecs
import signal
import subprocess
import sys
Expand Down Expand Up @@ -45,6 +46,17 @@ def set_sighdl_to_reset_timezone(timezone):
signal.signal(signal.SIGINT, lambda signal, frame: set_timezone_and_exit(timezone))


def setup_stdio():
(out_stream, err_stream) = (sys.stdout, sys.stderr)
if sys.version_info.major >= 3:
(out_stream, err_stream) = (sys.stdout.buffer, sys.stderr.buffer)
# For tty using native encoding, otherwise (pipe) use 'utf-8'
encoding = sys.stdout.encoding if sys.stdout.isatty() else 'utf-8'
# Always override it to anvoid encode error
sys.stdout = codecs.getwriter(encoding)(out_stream, 'xmlcharrefreplace')
sys.stderr = codecs.getwriter(encoding)(err_stream, 'xmlcharrefreplace')


def print_test_summary(summary_string, total, passed, failed):
print("\n[summary] %s\n" % summary_string)
print("TOTAL: %d" % total)
Expand Down