1#!/usr/bin/env python 2 3# Copyright JS Foundation and other contributors, http://js.foundation 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17from __future__ import print_function 18import signal 19import subprocess 20import sys 21 22TERM_NORMAL = '\033[0m' 23TERM_RED = '\033[1;31m' 24TERM_GREEN = '\033[1;32m' 25 26 27def set_timezone(timezone): 28 assert sys.platform == 'win32', "set_timezone is Windows only function" 29 subprocess.call(['cmd', '/S', '/C', 'tzutil', '/s', timezone]) 30 31 32def set_timezone_and_exit(timezone): 33 assert sys.platform == 'win32', "set_timezone_and_exit is Windows only function" 34 set_timezone(timezone) 35 sys.exit(1) 36 37 38def get_timezone(): 39 assert sys.platform == 'win32', "get_timezone is Windows only function" 40 return subprocess.check_output(['cmd', '/S', '/C', 'tzutil', '/g']) 41 42 43def set_sighdl_to_reset_timezone(timezone): 44 assert sys.platform == 'win32', "install_signal_handler_to_restore_timezone is Windows only function" 45 signal.signal(signal.SIGINT, lambda signal, frame: set_timezone_and_exit(timezone)) 46 47 48def print_test_summary(summary_string, total, passed, failed): 49 print("\n[summary] %s\n" % summary_string) 50 print("TOTAL: %d" % total) 51 print("%sPASS: %d%s" % (TERM_GREEN, passed, TERM_NORMAL)) 52 print("%sFAIL: %d%s\n" % (TERM_RED, failed, TERM_NORMAL)) 53 54 success_color = TERM_GREEN if passed == total else TERM_RED 55 print("%sSuccess: %d%%%s" % (success_color, passed*100/total, TERM_NORMAL)) 56 57 58def print_test_result(tested, total, is_passed, passed_string, test_path, is_snapshot_generation=None): 59 if is_snapshot_generation is None: 60 snapshot_string = '' 61 elif is_snapshot_generation: 62 snapshot_string = ' (generate snapshot)' 63 else: 64 snapshot_string = ' (execute snapshot)' 65 66 color = TERM_GREEN if is_passed else TERM_RED 67 print("[%4d/%4d] %s%s: %s%s%s" % (tested, total, color, passed_string, test_path, snapshot_string, TERM_NORMAL)) 68