Skip to content

Commit

Permalink
Bug 832750 - Improve python 3 compat in js/src/tests/; r=terrence
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed May 30, 2014
1 parent 4d1cdac commit a5e4e83
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 34 deletions.
8 changes: 5 additions & 3 deletions js/src/tests/jstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
See the adjacent README.txt for more details.
"""

from __future__ import print_function

import os, sys, textwrap
from os.path import abspath, dirname, realpath
from copy import copy
Expand Down Expand Up @@ -195,7 +197,7 @@ def parse_args():
options.show_output = True
try:
options.output_fp = open(options.output_file, 'w')
except IOError, ex:
except IOError as ex:
raise SystemExit("Failed to open output file: " + str(ex))

options.show = options.show_cmd or options.show_output
Expand Down Expand Up @@ -291,7 +293,7 @@ def main():
skip_list, test_list = load_tests(options, requested_paths, excluded_paths)

if not test_list:
print 'no tests selected'
print('no tests selected')
return 1

test_dir = dirname(abspath(__file__))
Expand All @@ -305,7 +307,7 @@ def main():

cmd = test_list[0].get_command(TestCase.js_cmd_prefix)
if options.show_cmd:
print list2cmdline(cmd)
print(list2cmdline(cmd))
if test_dir not in ('', '.'):
os.chdir(test_dir)
call(cmd)
Expand Down
6 changes: 4 additions & 2 deletions js/src/tests/lib/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#
# This includes classes for representing and parsing JS manifests.

import os, os.path, re, sys
from __future__ import print_function

import os, re, sys
from subprocess import Popen, PIPE

from tests import TestCase
Expand Down Expand Up @@ -166,7 +168,7 @@ def _parse_one(testcase, xul_tester):
testcase.expect = testcase.enable = False
pos += 1
else:
print 'warning: invalid manifest line element "%s"'%parts[pos]
print('warning: invalid manifest line element "%s"'%parts[pos])
pos += 1

def _build_manifest_script_entry(script_name, test):
Expand Down
24 changes: 13 additions & 11 deletions js/src/tests/lib/results.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import re
from progressbar import NullProgressBar, ProgressBar
import pipes
Expand Down Expand Up @@ -135,10 +137,10 @@ def push(self, output):

if show:
if self.options.show_output:
print >> self.fp, '## %s: rc = %d, run time = %f' % (output.test.path, output.rc, output.dt)
print('## %s: rc = %d, run time = %f' % (output.test.path, output.rc, output.dt), file=self.fp)

if self.options.show_cmd:
print >> self.fp, escape_cmdline(output.cmd)
print(escape_cmdline(output.cmd), file=self.fp)

if self.options.show_output:
self.fp.write(output.out)
Expand Down Expand Up @@ -199,28 +201,29 @@ def finish(self, completed):

def list(self, completed):
for label, paths in sorted(self.groups.items()):
if label == '': continue
if label == '':
continue

print label
print(label)
for path in paths:
print ' %s'%path
print(' %s' % path)

if self.options.failure_file:
failure_file = open(self.options.failure_file, 'w')
if not self.all_passed():
if 'REGRESSIONS' in self.groups:
for path in self.groups['REGRESSIONS']:
print >> failure_file, path
print(path, file=failure_file)
if 'TIMEOUTS' in self.groups:
for path in self.groups['TIMEOUTS']:
print >> failure_file, path
print(path, file=failure_file)
failure_file.close()

suffix = '' if completed else ' (partial run -- interrupted by user)'
if self.all_passed():
print 'PASS' + suffix
print('PASS' + suffix)
else:
print 'FAIL' + suffix
print('FAIL' + suffix)

def all_passed(self):
return 'REGRESSIONS' not in self.groups and 'TIMEOUTS' not in self.groups
Expand All @@ -235,5 +238,4 @@ def print_tinderbox_result(self, label, path, message=None, skip=False, time=Non
result += ' | (SKIP)'
if time > self.options.timeout:
result += ' | (TIMEOUT)'
print result

print(result)
2 changes: 1 addition & 1 deletion js/src/tests/lib/tasks_unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def reap_zombies(tasks, results, timeout):
pid, status = os.waitpid(0, os.WNOHANG)
if pid == 0:
break
except OSError, e:
except OSError as e:
if e.errno == errno.ECHILD:
break
raise e
Expand Down
10 changes: 7 additions & 3 deletions js/src/tests/lib/tasks_win.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Multiprocess activities with a push-driven divide-process-collect model.

from __future__ import print_function

from threading import Thread, Lock
from Queue import Queue, Empty
from datetime import datetime
Expand All @@ -19,12 +21,14 @@ def start(self, worker_count):

sink = Sink(self.results)
self.workers = [ Worker(_+1, self.tasks, sink, self.timeout, self.verbose) for _ in range(worker_count) ]
if self.verbose: print '[P] Starting workers.'
if self.verbose:
print('[P] Starting workers.')
for w in self.workers:
w.t0 = t0
w.start()
ans = self.join_workers()
if self.verbose: print '[P] Finished.'
if self.verbose:
print('[P] Finished.')
return ans

def join_workers(self):
Expand Down Expand Up @@ -66,7 +70,7 @@ def log(self, msg):
if self.verbose:
dd = datetime.now() - self.t0
dt = dd.seconds + 1e-6 * dd.microseconds
print '[W%d %.3f] %s' % (self.id, dt, msg)
print('[W%d %.3f] %s' % (self.id, dt, msg))

def run(self):
try:
Expand Down
30 changes: 16 additions & 14 deletions js/src/tests/parsemark.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
dirpath directory filled with parsilicious js files
"""

from __future__ import print_function

import math
import optparse
import os
Expand Down Expand Up @@ -77,9 +79,9 @@ def bench(shellpath, filepath, warmup_runs, counted_runs, stfu=False):
mean = avg(milliseconds)
sigma = stddev(milliseconds, mean)
if not stfu:
print 'Runs:', [int(ms) for ms in milliseconds]
print 'Mean:', mean
print 'Stddev: %.2f (%.2f%% of mean)' % (sigma, sigma / mean * 100)
print('Runs:', [int(ms) for ms in milliseconds])
print('Mean:', mean)
print('Stddev: %.2f (%.2f%% of mean)' % (sigma, sigma / mean * 100))
return mean, sigma


Expand All @@ -89,17 +91,17 @@ def parsemark(filepaths, fbench, stfu=False):
for filepath in filepaths:
filename = os.path.split(filepath)[-1]
if not stfu:
print 'Parsemarking %s...' % filename
print('Parsemarking %s...' % filename)
bench_map[filename] = fbench(filepath)
print '{'
print('{')
for i, (filename, (avg, stddev)) in enumerate(bench_map.iteritems()):
assert '"' not in filename
fmt = ' %30s: {"average_ms": %6.2f, "stddev_ms": %6.2f}'
if i != len(bench_map) - 1:
fmt += ','
filename_str = '"%s"' % filename
print fmt % (filename_str, avg, stddev)
print '}'
print(fmt % (filename_str, avg, stddev))
print('}')
return dict((filename, dict(average_ms=avg, stddev_ms=stddev))
for filename, (avg, stddev) in bench_map.iteritems())

Expand All @@ -122,25 +124,25 @@ def main():
shellpath = args.pop(0)
except IndexError:
parser.print_help()
print
print >> sys.stderr, 'error: shellpath required'
print()
print('error: shellpath required', file=sys.stderr)
return -1
try:
dirpath = args.pop(0)
except IndexError:
parser.print_help()
print
print >> sys.stderr, 'error: dirpath required'
print()
print('error: dirpath required', file=sys.stderr)
return -1
if not shellpath or not os.path.exists(shellpath):
print >> sys.stderr, 'error: could not find shell:', shellpath
print('error: could not find shell:', shellpath, file=sys.stderr)
return -1
if options.baseline_path:
if not os.path.isfile(options.baseline_path):
print >> sys.stderr, 'error: baseline file does not exist'
print('error: baseline file does not exist', file=sys.stderr)
return -1
if not compare_bench:
print >> sys.stderr, 'error: JSON support is missing, cannot compare benchmarks'
print('error: JSON support is missing, cannot compare benchmarks', file=sys.stderr)
return -1
benchfile = lambda filepath: bench(shellpath, filepath,
options.warmup_runs, options.counted_runs, stfu=options.stfu)
Expand Down

0 comments on commit a5e4e83

Please sign in to comment.