summaryrefslogtreecommitdiff
path: root/tools/test.py
diff options
context:
space:
mode:
authorcclauss <cclauss@bluewin.ch>2018-11-19 06:09:40 -0500
committerRefael Ackermann <refack@gmail.com>2018-11-25 18:58:58 -0500
commitb507783bc116d6703f374d1d096b057df51191be (patch)
tree3fadf92b7187c5995b1a617162b7b266966644cc /tools/test.py
parentf2432a47616979780e7ca76a935e5f05c4ee31b5 (diff)
downloadandroid-node-v8-b507783bc116d6703f374d1d096b057df51191be.tar.gz
android-node-v8-b507783bc116d6703f374d1d096b057df51191be.tar.bz2
android-node-v8-b507783bc116d6703f374d1d096b057df51191be.zip
tools: use print() function on both Python 2 and 3
PR-URL: https://github.com/nodejs/node/pull/24486 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'tools/test.py')
-rwxr-xr-xtools/test.py105
1 files changed, 53 insertions, 52 deletions
diff --git a/tools/test.py b/tools/test.py
index 67b8cb917e..640206f95c 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -28,6 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+from __future__ import print_function
import imp
import logging
import optparse
@@ -87,11 +88,11 @@ class ProgressIndicator(object):
negative_marker = '[negative] '
else:
negative_marker = ''
- print "=== %(label)s %(negative)s===" % {
+ print("=== %(label)s %(negative)s===" % {
'label': test.GetLabel(),
'negative': negative_marker
- }
- print "Path: %s" % "/".join(test.path)
+ })
+ print("Path: %s" % "/".join(test.path))
def Run(self, tasks):
self.Starting()
@@ -182,40 +183,40 @@ def EscapeCommand(command):
class SimpleProgressIndicator(ProgressIndicator):
def Starting(self):
- print 'Running %i tests' % len(self.cases)
+ print('Running %i tests' % len(self.cases))
def Done(self):
- print
+ print()
for failed in self.failed:
self.PrintFailureHeader(failed.test)
if failed.output.stderr:
- print "--- stderr ---"
- print failed.output.stderr.strip()
+ print("--- stderr ---")
+ print(failed.output.stderr.strip())
if failed.output.stdout:
- print "--- stdout ---"
- print failed.output.stdout.strip()
- print "Command: %s" % EscapeCommand(failed.command)
+ print("--- stdout ---")
+ print(failed.output.stdout.strip())
+ print("Command: %s" % EscapeCommand(failed.command))
if failed.HasCrashed():
- print "--- %s ---" % PrintCrashed(failed.output.exit_code)
+ print("--- %s ---" % PrintCrashed(failed.output.exit_code))
if failed.HasTimedOut():
- print "--- TIMEOUT ---"
+ print("--- TIMEOUT ---")
if len(self.failed) == 0:
- print "==="
- print "=== All tests succeeded"
- print "==="
+ print("===")
+ print("=== All tests succeeded")
+ print("===")
else:
- print
- print "==="
- print "=== %i tests failed" % len(self.failed)
+ print()
+ print("===")
+ print("=== %i tests failed" % len(self.failed))
if self.crashed > 0:
- print "=== %i tests CRASHED" % self.crashed
- print "==="
+ print("=== %i tests CRASHED" % self.crashed)
+ print("===")
class VerboseProgressIndicator(SimpleProgressIndicator):
def AboutToRun(self, case):
- print 'Starting %s...' % case.GetLabel()
+ print('Starting %s...' % case.GetLabel())
sys.stdout.flush()
def HasRun(self, output):
@@ -226,7 +227,7 @@ class VerboseProgressIndicator(SimpleProgressIndicator):
outcome = 'FAIL'
else:
outcome = 'pass'
- print 'Done running %s: %s' % (output.test.GetLabel(), outcome)
+ print('Done running %s: %s' % (output.test.GetLabel(), outcome))
class DotsProgressIndicator(SimpleProgressIndicator):
@@ -362,9 +363,9 @@ class DeoptsCheckProgressIndicator(SimpleProgressIndicator):
("because:" in line or "reason:" in line):
if not printed_file:
printed_file = True
- print '==== %s ====' % command
+ print('==== %s ====' % command)
self.failed.append(output)
- print ' %s' % line
+ print(' %s' % line)
def Done(self):
pass
@@ -393,15 +394,15 @@ class CompactProgressIndicator(ProgressIndicator):
self.PrintFailureHeader(output.test)
stdout = output.output.stdout.strip()
if len(stdout):
- print self.templates['stdout'] % stdout
+ print(self.templates['stdout'] % stdout)
stderr = output.output.stderr.strip()
if len(stderr):
- print self.templates['stderr'] % stderr
- print "Command: %s" % EscapeCommand(output.command)
+ print(self.templates['stderr'] % stderr)
+ print("Command: %s" % EscapeCommand(output.command))
if output.HasCrashed():
- print "--- %s ---" % PrintCrashed(output.output.exit_code)
+ print("--- %s ---" % PrintCrashed(output.output.exit_code))
if output.HasTimedOut():
- print "--- TIMEOUT ---"
+ print("--- TIMEOUT ---")
def Truncate(self, str, length):
if length and (len(str) > (length - 3)):
@@ -422,7 +423,7 @@ class CompactProgressIndicator(ProgressIndicator):
}
status = self.Truncate(status, 78)
self.last_status_length = len(status)
- print status,
+ print(status, end=' ')
sys.stdout.flush()
@@ -437,7 +438,7 @@ class ColorProgressIndicator(CompactProgressIndicator):
super(ColorProgressIndicator, self).__init__(cases, flaky_tests_mode, templates)
def ClearLine(self, last_line_length):
- print "\033[1K\r",
+ print("\033[1K\r", end=' ')
class MonochromeProgressIndicator(CompactProgressIndicator):
@@ -453,7 +454,7 @@ class MonochromeProgressIndicator(CompactProgressIndicator):
super(MonochromeProgressIndicator, self).__init__(cases, flaky_tests_mode, templates)
def ClearLine(self, last_line_length):
- print ("\r" + (" " * last_line_length) + "\r"),
+ print(("\r" + (" " * last_line_length) + "\r"), end=' ')
PROGRESS_INDICATORS = {
@@ -616,7 +617,7 @@ def KillTimedOutProcess(context, pid):
def RunProcess(context, timeout, args, **rest):
- if context.verbose: print "#", " ".join(args)
+ if context.verbose: print("#", " ".join(args))
popen_args = args
prev_error_mode = SEM_INVALID_VALUE;
if utils.IsWindows():
@@ -1181,15 +1182,15 @@ def ParseCondition(expr):
"""Parses a logical expression into an Expression object"""
tokens = Tokenizer(expr).Tokenize()
if not tokens:
- print "Malformed expression: '%s'" % expr
+ print("Malformed expression: '%s'" % expr)
return None
scan = Scanner(tokens)
ast = ParseLogicalExpression(scan)
if not ast:
- print "Malformed expression: '%s'" % expr
+ print("Malformed expression: '%s'" % expr)
return None
if scan.HasMore():
- print "Malformed expression: '%s'" % expr
+ print("Malformed expression: '%s'" % expr)
return None
return ast
@@ -1387,19 +1388,19 @@ def ProcessOptions(options):
if options.run == [""]:
options.run = None
elif len(options.run) != 2:
- print "The run argument must be two comma-separated integers."
+ print("The run argument must be two comma-separated integers.")
return False
else:
try:
options.run = map(int, options.run)
except ValueError:
- print "Could not parse the integers from the run argument."
+ print("Could not parse the integers from the run argument.")
return False
if options.run[0] < 0 or options.run[1] < 0:
- print "The run argument cannot have negative integers."
+ print("The run argument cannot have negative integers.")
return False
if options.run[0] >= options.run[1]:
- print "The test group to run (n) must be smaller than number of groups (m)."
+ print("The test group to run (n) must be smaller than number of groups (m).")
return False
if options.J:
# inherit JOBS from environment if provided. some virtualised systems
@@ -1407,7 +1408,7 @@ def ProcessOptions(options):
cores = os.environ.get('JOBS')
options.j = int(cores) if cores is not None else multiprocessing.cpu_count()
if options.flaky_tests not in [RUN, SKIP, DONTCARE]:
- print "Unknown flaky-tests mode %s" % options.flaky_tests
+ print("Unknown flaky-tests mode %s" % options.flaky_tests)
return False
return True
@@ -1606,13 +1607,13 @@ def Main():
for mode in options.mode:
vm = context.GetVm(arch, mode)
if not exists(vm):
- print "Can't find shell executable: '%s'" % vm
+ print("Can't find shell executable: '%s'" % vm)
continue
archEngineContext = Execute([vm, "-p", "process.arch"], context)
vmArch = archEngineContext.stdout.rstrip()
if archEngineContext.exit_code is not 0 or vmArch == "undefined":
- print "Can't determine the arch of: '%s'" % vm
- print archEngineContext.stderr.rstrip()
+ print("Can't determine the arch of: '%s'" % vm)
+ print(archEngineContext.stderr.rstrip())
continue
env = {
'mode': mode,
@@ -1649,15 +1650,15 @@ def Main():
if key in visited:
continue
visited.add(key)
- print "--- begin source: %s ---" % test.GetLabel()
+ print("--- begin source: %s ---" % test.GetLabel())
source = test.GetSource().strip()
- print source
- print "--- end source: %s ---" % test.GetLabel()
+ print(source)
+ print("--- end source: %s ---" % test.GetLabel())
return 0
if options.warn_unused:
for rule in globally_unused_rules:
- print "Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path])
+ print("Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path]))
tempdir = os.environ.get('NODE_TEST_DIR') or options.temp_dir
if tempdir:
@@ -1666,7 +1667,7 @@ def Main():
os.makedirs(tempdir)
except OSError as exception:
if exception.errno != errno.EEXIST:
- print "Could not create the temporary directory", options.temp_dir
+ print("Could not create the temporary directory", options.temp_dir)
sys.exit(1)
def should_keep(case):
@@ -1700,7 +1701,7 @@ def Main():
len(cases_to_run),
options.run[1]) ]
if len(cases_to_run) == 0:
- print "No tests to run."
+ print("No tests to run.")
return 1
else:
try:
@@ -1711,13 +1712,13 @@ def Main():
result = 1
duration = time.time() - start
except KeyboardInterrupt:
- print "Interrupted"
+ print("Interrupted")
return 1
if options.time:
# Write the times to stderr to make it easy to separate from the
# test output.
- print
+ print()
sys.stderr.write("--- Total time: %s ---\n" % FormatTime(duration))
timed_tests = [ t for t in cases_to_run if not t.duration is None ]
timed_tests.sort(lambda a, b: a.CompareTime(b))