From b507783bc116d6703f374d1d096b057df51191be Mon Sep 17 00:00:00 2001 From: cclauss Date: Mon, 19 Nov 2018 06:09:40 -0500 Subject: tools: use print() function on both Python 2 and 3 PR-URL: https://github.com/nodejs/node/pull/24486 Reviewed-By: Anna Henningsen Reviewed-By: James M Snell Reviewed-By: Refael Ackermann Reviewed-By: Sakthipriyan Vairamani --- tools/test.py | 105 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 53 insertions(+), 52 deletions(-) (limited to 'tools/test.py') 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)) -- cgit v1.2.3