diff options
-rw-r--r-- | .flake8 | 2 | ||||
-rwxr-xr-x | configure.py | 2 | ||||
-rw-r--r-- | test/message/testcfg.py | 25 | ||||
-rw-r--r-- | test/pseudo-tty/testcfg.py | 41 | ||||
-rw-r--r-- | test/testpy/__init__.py | 44 | ||||
-rw-r--r-- | tools/getmoduleversion.py | 4 | ||||
-rwxr-xr-x | tools/install.py | 23 | ||||
-rwxr-xr-x | tools/js2c.py | 15 | ||||
-rwxr-xr-x | tools/test.py | 50 |
9 files changed, 81 insertions, 125 deletions
@@ -1,3 +1,3 @@ [flake8] exclude=.git,deps,lib,src,tools/gyp,tools/inspector_protocol,tools/pip,tools/v8_gypfiles/broken -select=E9,F63,F72,F82 +ignore=E1,E2,E3,E4,E5,E7,W5,W6 diff --git a/configure.py b/configure.py index d78a1caf64..f32e82e6f2 100755 --- a/configure.py +++ b/configure.py @@ -1110,7 +1110,7 @@ def configure_library(lib, output): output['libraries'] += [pkg_libpath] default_libs = getattr(options, shared_lib + '_libname') - default_libs = ['-l{0}'.format(lib) for lib in default_libs.split(',')] + default_libs = ['-l{0}'.format(l) for l in default_libs.split(',')] if default_libs: output['libraries'] += default_libs diff --git a/test/message/testcfg.py b/test/message/testcfg.py index a4f802f3ef..bd56a8eba8 100644 --- a/test/message/testcfg.py +++ b/test/message/testcfg.py @@ -30,16 +30,7 @@ import test import os from os.path import join, exists, basename, isdir import re - -try: - reduce # Python 2 -except NameError: # Python 3 - from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 +from functools import reduce FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") @@ -82,13 +73,13 @@ class MessageTestCase(test.TestCase): print("expect=%d" % len(patterns)) print("actual=%d" % len(outlines)) print("patterns:") - for i in xrange(len(patterns)): + for i in range(len(patterns)): print("pattern = %s" % patterns[i]) print("outlines:") - for i in xrange(len(outlines)): + for i in range(len(outlines)): print("outline = %s" % outlines[i]) return True - for i in xrange(len(patterns)): + for i in range(len(patterns)): if not re.match(patterns[i], outlines[i]): print("match failed") print("line=%d" % i) @@ -129,13 +120,13 @@ class MessageTestConfiguration(test.TestConfiguration): def ListTests(self, current_path, path, arch, mode): all_tests = [current_path + [t] for t in self.Ls(self.root)] result = [] - for test in all_tests: - if self.Contains(path, test): - file_path = join(self.root, reduce(join, test[1:], '')) + for tst in all_tests: + if self.Contains(path, tst): + file_path = join(self.root, reduce(join, tst[1:], '')) output_path = file_path[:file_path.rfind('.')] + '.out' if not exists(output_path): raise Exception("Could not find %s" % output_path) - result.append(MessageTestCase(test, file_path, output_path, + result.append(MessageTestCase(tst, file_path, output_path, arch, mode, self.context, self)) return result diff --git a/test/pseudo-tty/testcfg.py b/test/pseudo-tty/testcfg.py index c12a16f805..f2a7242e83 100644 --- a/test/pseudo-tty/testcfg.py +++ b/test/pseudo-tty/testcfg.py @@ -32,34 +32,25 @@ import os from os.path import join, exists, basename, isdir import re import utils - -try: - reduce # Python 2 -except NameError: # Python 3 - from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 +from functools import reduce FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") class TTYTestCase(test.TestCase): - def __init__(self, path, file, expected, input, arch, mode, context, config): + def __init__(self, path, file, expected, input_arg, arch, mode, context, config): super(TTYTestCase, self).__init__(context, path, arch, mode) self.file = file self.expected = expected - self.input = input + self.input = input_arg self.config = config self.arch = arch self.mode = mode - def IgnoreLine(self, str): + def IgnoreLine(self, str_arg): """Ignore empty lines and valgrind output.""" - if not str.strip(): return True - else: return str.startswith('==') or str.startswith('**') + if not str_arg.strip(): return True + else: return str_arg.startswith('==') or str_arg.startswith('**') def IsFailureOutput(self, output): f = open(self.expected) @@ -81,13 +72,13 @@ class TTYTestCase(test.TestCase): print("expect=%d" % len(patterns)) print("actual=%d" % len(outlines)) print("patterns:") - for i in xrange(len(patterns)): + for i in range(len(patterns)): print("pattern = %s" % patterns[i]) print("outlines:") - for i in xrange(len(outlines)): + for i in range(len(outlines)): print("outline = %s" % outlines[i]) return True - for i in xrange(len(patterns)): + for i in range(len(patterns)): if not re.match(patterns[i], outlines[i]): print("match failed") print("line=%d" % i) @@ -117,16 +108,16 @@ class TTYTestCase(test.TestCase): + open(self.expected).read()) def RunCommand(self, command, env): - input = None + input_arg = None if self.input is not None and exists(self.input): - input = open(self.input).read() + input_arg = open(self.input).read() full_command = self.context.processor(command) output = test.Execute(full_command, self.context, self.context.GetTimeout(self.mode), env, faketty=True, - input=input) + input=input_arg) return test.TestOutput(self, full_command, output, @@ -148,15 +139,15 @@ class TTYTestConfiguration(test.TestConfiguration): print ("Skipping pseudo-tty tests, as pseudo terminals are not available" " on Windows.") return result - for test in all_tests: - if self.Contains(path, test): - file_prefix = join(self.root, reduce(join, test[1:], "")) + for tst in all_tests: + if self.Contains(path, tst): + file_prefix = join(self.root, reduce(join, tst[1:], "")) file_path = file_prefix + ".js" input_path = file_prefix + ".in" output_path = file_prefix + ".out" if not exists(output_path): raise Exception("Could not find %s" % output_path) - result.append(TTYTestCase(test, file_path, output_path, + result.append(TTYTestCase(tst, file_path, output_path, input_path, arch, mode, self.context, self)) return result diff --git a/test/testpy/__init__.py b/test/testpy/__init__.py index 332284ce4c..9c70e18d6a 100644 --- a/test/testpy/__init__.py +++ b/test/testpy/__init__.py @@ -27,18 +27,12 @@ import test import os -from os.path import join, dirname, exists, splitext import re -import ast - -try: - reduce -except NameError: - from functools import reduce +from functools import reduce FLAGS_PATTERN = re.compile(r"//\s+Flags:(.*)") - +LS_RE = re.compile(r'^test-.*\.m?js$') class SimpleTestCase(test.TestCase): @@ -107,15 +101,15 @@ class SimpleTestConfiguration(test.TestConfiguration): self.additional_flags = [] def Ls(self, path): - return [f for f in os.listdir(path) if re.match('^test-.*\.m?js$', f)] + return [f for f in os.listdir(path) if LS_RE.match(f)] def ListTests(self, current_path, path, arch, mode): - all_tests = [current_path + [t] for t in self.Ls(join(self.root))] + all_tests = [current_path + [t] for t in self.Ls(os.path.join(self.root))] result = [] - for test in all_tests: - if self.Contains(path, test): - file_path = join(self.root, reduce(join, test[1:], "")) - test_name = test[:-1] + [splitext(test[-1])[0]] + for tst in all_tests: + if self.Contains(path, tst): + file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "")) + test_name = tst[:-1] + [os.path.splitext(tst[-1])[0]] result.append(SimpleTestCase(test_name, file_path, arch, mode, self.context, self, self.additional_flags)) return result @@ -131,8 +125,8 @@ class ParallelTestConfiguration(SimpleTestConfiguration): def ListTests(self, current_path, path, arch, mode): result = super(ParallelTestConfiguration, self).ListTests( current_path, path, arch, mode) - for test in result: - test.parallel = True + for tst in result: + tst.parallel = True return result class AddonTestConfiguration(SimpleTestConfiguration): @@ -145,20 +139,20 @@ class AddonTestConfiguration(SimpleTestConfiguration): result = [] for subpath in os.listdir(path): - if os.path.isdir(join(path, subpath)): - for f in os.listdir(join(path, subpath)): + if os.path.isdir(os.path.join(path, subpath)): + for f in os.listdir(os.path.join(path, subpath)): if SelectTest(f): result.append([subpath, f[:-3]]) return result def ListTests(self, current_path, path, arch, mode): - all_tests = [current_path + t for t in self.Ls(join(self.root))] + all_tests = [current_path + t for t in self.Ls(os.path.join(self.root))] result = [] - for test in all_tests: - if self.Contains(path, test): - file_path = join(self.root, reduce(join, test[1:], "") + ".js") + for tst in all_tests: + if self.Contains(path, tst): + file_path = os.path.join(self.root, reduce(os.path.join, tst[1:], "") + ".js") result.append( - SimpleTestCase(test, file_path, arch, mode, self.context, self, self.additional_flags)) + SimpleTestCase(tst, file_path, arch, mode, self.context, self, self.additional_flags)) return result class AbortTestConfiguration(SimpleTestConfiguration): @@ -169,6 +163,6 @@ class AbortTestConfiguration(SimpleTestConfiguration): def ListTests(self, current_path, path, arch, mode): result = super(AbortTestConfiguration, self).ListTests( current_path, path, arch, mode) - for test in result: - test.disable_core_files = True + for tst in result: + tst.disable_core_files = True return result diff --git a/tools/getmoduleversion.py b/tools/getmoduleversion.py index fb86ba1fa9..5a88fa6318 100644 --- a/tools/getmoduleversion.py +++ b/tools/getmoduleversion.py @@ -2,6 +2,7 @@ from __future__ import print_function import os import re + def get_version(): node_version_h = os.path.join( os.path.dirname(__file__), @@ -17,8 +18,9 @@ def get_version(): if re.match(regex, line): major = line.split()[2] return major - + raise Exception('Could not find pattern matching %s' % regex) + if __name__ == '__main__': print(get_version()) diff --git a/tools/install.py b/tools/install.py index 3befec213b..655802980a 100755 --- a/tools/install.py +++ b/tools/install.py @@ -1,17 +1,16 @@ #!/usr/bin/env python from __future__ import print_function + import ast import errno import os -import re import shutil import sys -from getmoduleversion import get_version # set at init time node_prefix = '/usr/local' # PREFIX variable from Makefile -install_path = None # base target directory (DESTDIR + PREFIX from Makefile) +install_path = '' # base target directory (DESTDIR + PREFIX from Makefile) target_defaults = None variables = None @@ -101,7 +100,7 @@ def npm_files(action): elif action == install: try_symlink('../lib/node_modules/npm/bin/npm-cli.js', link_path) else: - assert(0) # unhandled action type + assert 0 # unhandled action type # create/remove symlink link_path = abspath(install_path, 'bin/npx') @@ -110,15 +109,15 @@ def npm_files(action): elif action == install: try_symlink('../lib/node_modules/npm/bin/npx-cli.js', link_path) else: - assert(0) # unhandled action type + assert 0 # unhandled action type def subdir_files(path, dest, action): ret = {} for dirpath, dirnames, filenames in os.walk(path): - files = [dirpath + '/' + f for f in filenames if f.endswith('.h')] - ret[dest + dirpath.replace(path, '')] = files - for subdir, files in ret.items(): - action(files, subdir + '/') + files_in_path = [dirpath + '/' + f for f in filenames if f.endswith('.h')] + ret[dest + dirpath.replace(path, '')] = files_in_path + for subdir, files_in_path in ret.items(): + action(files_in_path, subdir + '/') def files(action): is_windows = sys.platform == 'win32' @@ -162,13 +161,13 @@ def files(action): headers(action) def headers(action): - def ignore_inspector_headers(files, dest): + def ignore_inspector_headers(files_arg, dest): inspector_headers = [ 'deps/v8/include/v8-inspector.h', 'deps/v8/include/v8-inspector-protocol.h' ] - files = [name for name in files if name not in inspector_headers] - action(files, dest) + files_arg = [name for name in files_arg if name not in inspector_headers] + action(files_arg, dest) action([ 'common.gypi', diff --git a/tools/js2c.py b/tools/js2c.py index d7d0c710b1..86648f785c 100755 --- a/tools/js2c.py +++ b/tools/js2c.py @@ -34,17 +34,10 @@ import os import re import sys -import string -import hashlib - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 def ToCArray(elements, step=10): - slices = (elements[i:i+step] for i in xrange(0, len(elements), step)) + slices = (elements[i:i+step] for i in range(0, len(elements), step)) slices = map(lambda s: ','.join(str(x) for x in s), slices) return ',\n'.join(slices) @@ -160,14 +153,14 @@ def ReadMacros(lines): macro_match = MACRO_PATTERN.match(line) if macro_match: name = macro_match.group(1) - args = map(string.strip, macro_match.group(2).split(',')) + args = [s.strip() for s in macro_match.group(2).split(',')] body = macro_match.group(3).strip() macros[name] = TextMacro(args, body) else: python_match = PYTHON_MACRO_PATTERN.match(line) if python_match: name = python_match.group(1) - args = map(string.strip, python_match.group(2).split(',')) + args = [s.strip() for s in python_match.group(2).split(',')] body = python_match.group(3).strip() fun = eval("lambda " + ",".join(args) + ': ' + body) macros[name] = PythonMacro(args, fun) @@ -238,7 +231,7 @@ def JS2C(source, target): # Treat non-ASCII as UTF-8 and convert it to UTF-16. if any(ord(c) > 127 for c in source): source = map(ord, source.decode('utf-8').encode('utf-16be')) - source = [source[i] * 256 + source[i+1] for i in xrange(0, len(source), 2)] + source = [source[i] * 256 + source[i+1] for i in range(0, len(source), 2)] source = ToCArray(source) return TWO_BYTE_STRING.format(var=var, data=source) else: diff --git a/tools/test.py b/tools/test.py index d58ffd5648..2247db3635 100755 --- a/tools/test.py +++ b/tools/test.py @@ -52,21 +52,7 @@ try: except ImportError: from Queue import Queue, Empty # Python 2 -try: - cmp # Python 2 -except NameError: - def cmp(x, y): # Python 3 - return (x > y) - (x < y) - -try: - reduce # Python 2 -except NameError: # Python 3 - from functools import reduce - -try: - xrange # Python 2 -except NameError: - xrange = range # Python 3 +from functools import reduce try: from urllib.parse import unquote # Python 3 @@ -135,9 +121,9 @@ class ProgressIndicator(object): for thread in threads: # Use a timeout so that signals (ctrl-c) will be processed. thread.join(timeout=10000000) - except (KeyboardInterrupt, SystemExit) as e: + except (KeyboardInterrupt, SystemExit): self.shutdown_event.set() - except Exception as e: + except Exception: # If there's an exception we schedule an interruption for any # remaining threads. self.shutdown_event.set() @@ -174,7 +160,7 @@ class ProgressIndicator(object): output = case.Run() output.diagnostic.append('ECONNREFUSED received, test retried') case.duration = (datetime.now() - start) - except IOError as e: + except IOError: return if self.shutdown_event.is_set(): return @@ -383,9 +369,10 @@ class DeoptsCheckProgressIndicator(SimpleProgressIndicator): stdout = output.output.stdout.strip() printed_file = False for line in stdout.splitlines(): - if (line.startswith("[aborted optimiz") or \ - line.startswith("[disabled optimiz")) and \ - ("because:" in line or "reason:" in line): + if ( + (line.startswith("[aborted optimiz") or line.startswith("[disabled optimiz")) and + ("because:" in line or "reason:" in line) + ): if not printed_file: printed_file = True print('==== %s ====' % command) @@ -522,9 +509,6 @@ class TestCase(object): def IsNegative(self): return self.context.expect_fail - def CompareTime(self, other): - return cmp(other.duration, self.duration) - def DidFail(self, output): if output.failed is None: output.failed = self.IsFailureOutput(output) @@ -597,7 +581,7 @@ class TestOutput(object): return self.output.exit_code < 0 def HasTimedOut(self): - return self.output.timed_out; + return self.output.timed_out def HasFailed(self): execution_failed = self.test.DidFail(self.output) @@ -731,7 +715,9 @@ def CheckedUnlink(name): PrintError("os.unlink() " + str(e)) break -def Execute(args, context, timeout=None, env={}, faketty=False, disable_core_files=False, input=None): +def Execute(args, context, timeout=None, env=None, faketty=False, disable_core_files=False, input=None): + if env is None: + env = {} if faketty: import pty (out_master, fd_out) = pty.openpty() @@ -897,7 +883,7 @@ class LiteralTestSuite(TestSuite): if not name or name.match(test_name): full_path = current_path + [test_name] test.AddTestsToList(result, full_path, path, context, arch, mode) - result.sort(cmp=lambda a, b: cmp(a.GetName(), b.GetName())) + result.sort(key=lambda x: x.GetName()) return result def GetTestStatus(self, context, sections, defs): @@ -1283,7 +1269,7 @@ class Rule(object): HEADER_PATTERN = re.compile(r'\[([^]]+)\]') RULE_PATTERN = re.compile(r'\s*([^: ]*)\s*:(.*)') DEF_PATTERN = re.compile(r'^def\s*(\w+)\s*=(.*)$') -PREFIX_PATTERN = re.compile(r'^\s*prefix\s+([\w\_\.\-\/]+)$') +PREFIX_PATTERN = re.compile(r'^\s*prefix\s+([\w_.\-/]+)$') def ReadConfigurationInto(path, sections, defs): @@ -1470,9 +1456,9 @@ class Pattern(object): return self.pattern -def SplitPath(s): - stripped = [ c.strip() for c in s.split('/') ] - return [ Pattern(s) for s in stripped if len(s) > 0 ] +def SplitPath(path_arg): + stripped = [c.strip() for c in path_arg.split('/')] + return [Pattern(s) for s in stripped if len(s) > 0] def NormalizePath(path, prefix='test/'): # strip the extra path information of the specified test @@ -1753,7 +1739,7 @@ def Main(): 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)) + timed_tests.sort(key=lambda x: x.duration) for i, entry in enumerate(timed_tests[:20], start=1): t = FormatTimedelta(entry.duration) sys.stderr.write("%4i (%s) %s\n" % (i, t, entry.GetLabel())) |