Fix flake 8 style warnings

Ran zts-report.py and test-runner.py from ./tests/test-runner/bin/
through the 2to3 (https://docs.python.org/2/library/2to3.html).
Checked the result, fixed:
- 'maxint' -> 'maxsize' that 2to3 missed.
- 'cmp=' parameter for a 'sorted()' with a 'key=' version.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed by: John Wren Kennedy <jwk404@gmail.com>
Signed-off-by: Gregor Kopka <gregor@kopka.net>
Closes #7925 
Closes #7929
This commit is contained in:
Gregor Kopka 2018-09-24 19:12:59 +02:00 committed by Brian Behlendorf
parent dda5500853
commit b8fd4310c5
2 changed files with 37 additions and 35 deletions

View File

@ -16,7 +16,7 @@
# Copyright (c) 2017 Datto Inc. # Copyright (c) 2017 Datto Inc.
# #
import ConfigParser import configparser
import os import os
import logging import logging
from datetime import datetime from datetime import datetime
@ -27,7 +27,7 @@ from select import select
from subprocess import PIPE from subprocess import PIPE
from subprocess import Popen from subprocess import Popen
from sys import argv from sys import argv
from sys import maxint from sys import maxsize
from threading import Timer from threading import Timer
from time import time from time import time
@ -204,23 +204,23 @@ class Cmd(object):
if needed. Run the command, and update the result object. if needed. Run the command, and update the result object.
""" """
if options.dryrun is True: if options.dryrun is True:
print self print(self)
return return
privcmd = self.update_cmd_privs(self.pathname, self.user) privcmd = self.update_cmd_privs(self.pathname, self.user)
try: try:
old = os.umask(0) old = os.umask(0)
if not os.path.isdir(self.outputdir): if not os.path.isdir(self.outputdir):
os.makedirs(self.outputdir, mode=0777) os.makedirs(self.outputdir, mode=0o777)
os.umask(old) os.umask(old)
except OSError, e: except OSError as e:
fail('%s' % e) fail('%s' % e)
self.result.starttime = time() self.result.starttime = time()
proc = Popen(privcmd, stdout=PIPE, stderr=PIPE) proc = Popen(privcmd, stdout=PIPE, stderr=PIPE)
# Allow a special timeout value of 0 to mean infinity # Allow a special timeout value of 0 to mean infinity
if int(self.timeout) == 0: if int(self.timeout) == 0:
self.timeout = maxint self.timeout = maxsize
t = Timer(int(self.timeout), self.kill_cmd, [proc]) t = Timer(int(self.timeout), self.kill_cmd, [proc])
try: try:
@ -274,7 +274,7 @@ class Cmd(object):
logger.debug('%s%s%s' % (msga, pad, msgb)) logger.debug('%s%s%s' % (msga, pad, msgb))
lines = sorted(self.result.stdout + self.result.stderr, lines = sorted(self.result.stdout + self.result.stderr,
cmp=lambda x, y: cmp(x[0], y[0])) key=lambda x: x[0])
for dt, line in lines: for dt, line in lines:
logger.debug('%s %s' % (dt.strftime("%H:%M:%S.%f ")[:11], line)) logger.debug('%s %s' % (dt.strftime("%H:%M:%S.%f ")[:11], line))
@ -552,7 +552,7 @@ class TestRun(object):
in the 'DEFAULT' section. If the Test or TestGroup passes in the 'DEFAULT' section. If the Test or TestGroup passes
verification, add it to the TestRun. verification, add it to the TestRun.
""" """
config = ConfigParser.RawConfigParser() config = configparser.RawConfigParser()
if not len(config.read(options.runfile)): if not len(config.read(options.runfile)):
fail("Coulnd't read config file %s" % options.runfile) fail("Coulnd't read config file %s" % options.runfile)
@ -608,7 +608,7 @@ class TestRun(object):
defaults = dict([(prop, getattr(options, prop)) for prop, _ in defaults = dict([(prop, getattr(options, prop)) for prop, _ in
self.defaults]) self.defaults])
config = ConfigParser.RawConfigParser(defaults) config = configparser.RawConfigParser(defaults)
for test in sorted(self.tests.keys()): for test in sorted(self.tests.keys()):
config.add_section(test) config.add_section(test)
@ -637,14 +637,15 @@ class TestRun(object):
""" """
done = False done = False
components = 0 components = 0
tmp_dict = dict(self.tests.items() + self.testgroups.items()) tmp_dict = dict(list(self.tests.items()) +
list(self.testgroups.items()))
total = len(tmp_dict) total = len(tmp_dict)
base = self.outputdir base = self.outputdir
while not done: while not done:
paths = [] paths = []
components -= 1 components -= 1
for testfile in tmp_dict.keys(): for testfile in list(tmp_dict.keys()):
uniq = '/'.join(testfile.split('/')[components:]).lstrip('/') uniq = '/'.join(testfile.split('/')[components:]).lstrip('/')
if uniq not in paths: if uniq not in paths:
paths.append(uniq) paths.append(uniq)
@ -672,9 +673,9 @@ class TestRun(object):
if options.cmd is not 'wrconfig': if options.cmd is not 'wrconfig':
try: try:
old = os.umask(0) old = os.umask(0)
os.makedirs(self.outputdir, mode=0777) os.makedirs(self.outputdir, mode=0o777)
os.umask(old) os.umask(old)
except OSError, e: except OSError as e:
fail('%s' % e) fail('%s' % e)
filename = os.path.join(self.outputdir, 'log') filename = os.path.join(self.outputdir, 'log')
@ -707,8 +708,8 @@ class TestRun(object):
if not os.path.exists(logsymlink): if not os.path.exists(logsymlink):
os.symlink(self.outputdir, logsymlink) os.symlink(self.outputdir, logsymlink)
else: else:
print 'Could not make a symlink to directory %s' % ( print('Could not make a symlink to directory %s' % (
self.outputdir) self.outputdir))
iteration = 0 iteration = 0
while iteration < options.iterations: while iteration < options.iterations:
for test in sorted(self.tests.keys()): for test in sorted(self.tests.keys()):
@ -721,17 +722,17 @@ class TestRun(object):
if Result.total is 0: if Result.total is 0:
return 2 return 2
print '\nResults Summary' print('\nResults Summary')
for key in Result.runresults.keys(): for key in list(Result.runresults.keys()):
if Result.runresults[key] is not 0: if Result.runresults[key] is not 0:
print '%s\t% 4d' % (key, Result.runresults[key]) print('%s\t% 4d' % (key, Result.runresults[key]))
m, s = divmod(time() - self.starttime, 60) m, s = divmod(time() - self.starttime, 60)
h, m = divmod(m, 60) h, m = divmod(m, 60)
print '\nRunning Time:\t%02d:%02d:%02d' % (h, m, s) print('\nRunning Time:\t%02d:%02d:%02d' % (h, m, s))
print 'Percent passed:\t%.1f%%' % ((float(Result.runresults['PASS']) / print('Percent passed:\t%.1f%%' % ((float(Result.runresults['PASS']) /
float(Result.total)) * 100) float(Result.total)) * 100))
print 'Log directory:\t%s' % self.outputdir print('Log directory:\t%s' % self.outputdir)
if Result.runresults['FAIL'] > 0: if Result.runresults['FAIL'] > 0:
return 1 return 1
@ -804,7 +805,7 @@ def find_tests(testrun, options):
def fail(retstr, ret=1): def fail(retstr, ret=1):
print '%s: %s' % (argv[0], retstr) print('%s: %s' % (argv[0], retstr))
exit(ret) exit(ret)

View File

@ -278,15 +278,15 @@ maybe = {
def usage(s): def usage(s):
print s print(s)
sys.exit(1) sys.exit(1)
def process_results(pathname): def process_results(pathname):
try: try:
f = open(pathname) f = open(pathname)
except IOError, e: except IOError as e:
print 'Error opening file: %s' % e print('Error opening file: %s' % e)
sys.exit(1) sys.exit(1)
prefix = '/zfs-tests/tests/functional/' prefix = '/zfs-tests/tests/functional/'
@ -317,14 +317,14 @@ if __name__ == "__main__":
results = process_results(sys.argv[1]) results = process_results(sys.argv[1])
if summary['total'] == 0: if summary['total'] == 0:
print "\n\nNo test results were found." print("\n\nNo test results were found.")
print "Log directory: %s" % summary['logfile'] print("Log directory: %s" % summary['logfile'])
sys.exit(0) sys.exit(0)
expected = [] expected = []
unexpected = [] unexpected = []
for test in results.keys(): for test in list(results.keys()):
if results[test] == "PASS": if results[test] == "PASS":
continue continue
@ -341,7 +341,7 @@ if __name__ == "__main__":
else: else:
expected.append(test) expected.append(test)
print "\nTests with results other than PASS that are expected:" print("\nTests with results other than PASS that are expected:")
for test in sorted(expected): for test in sorted(expected):
issue_url = 'https://github.com/zfsonlinux/zfs/issues/' issue_url = 'https://github.com/zfsonlinux/zfs/issues/'
@ -367,20 +367,21 @@ if __name__ == "__main__":
continue continue
else: else:
expect = "UNKNOWN REASON" expect = "UNKNOWN REASON"
print " %s %s (%s)" % (results[test], test, expect) print(" %s %s (%s)" % (results[test], test, expect))
print "\nTests with result of PASS that are unexpected:" print("\nTests with result of PASS that are unexpected:")
for test in sorted(known.keys()): for test in sorted(known.keys()):
# We probably should not be silently ignoring the case # We probably should not be silently ignoring the case
# where "test" is not in "results". # where "test" is not in "results".
if test not in results or results[test] != "PASS": if test not in results or results[test] != "PASS":
continue continue
print " %s %s (expected %s)" % (results[test], test, known[test][0]) print(" %s %s (expected %s)" % (results[test], test,
known[test][0]))
print "\nTests with results other than PASS that are unexpected:" print("\nTests with results other than PASS that are unexpected:")
for test in sorted(unexpected): for test in sorted(unexpected):
expect = "PASS" if test not in known else known[test][0] expect = "PASS" if test not in known else known[test][0]
print " %s %s (expected %s)" % (results[test], test, expect) print(" %s %s (expected %s)" % (results[test], test, expect))
if len(unexpected) == 0: if len(unexpected) == 0:
sys.exit(0) sys.exit(0)