aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <Cristian.Maureira-Fredes@qt.io>2020-12-31 01:29:43 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-03 13:15:46 +0000
commite034bcde27a75a96059352b5ef4d1af430d6be23 (patch)
treefcd2d62a25a4aa9d42951f174e86e43759ec76a0
parent466c2e0078df4563df179dbbd014a52887e5f273 (diff)
testing: solve flake8 warnings
Change-Id: I75f1a367c8a86ec586820bd4a45339773c15a70a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 2de3a763fa18d5c30c2cff25057f1b81ceeed231) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--testing/blacklist.py9
-rw-r--r--testing/buildlog.py5
-rw-r--r--testing/command.py36
-rw-r--r--testing/helper.py18
-rw-r--r--testing/parser.py5
-rw-r--r--testing/runner.py14
-rw-r--r--testing/wheel_tester.py19
7 files changed, 51 insertions, 55 deletions
diff --git a/testing/blacklist.py b/testing/blacklist.py
index 48ace7af7..3de29ce05 100644
--- a/testing/blacklist.py
+++ b/testing/blacklist.py
@@ -45,13 +45,14 @@ Take a blacklist file and build classifiers for all tests.
find_matching_line() adds info using classifiers.
"""
-from .helper import decorate, StringIO
+from io import StringIO
+from .helper import decorate
from .buildlog import builds
class BlackList(object):
def __init__(self, blname):
- if blname == None:
+ if not blname:
f = StringIO()
self.raw_data = []
else:
@@ -62,7 +63,7 @@ class BlackList(object):
def filtered_line(line):
if '#' in line:
- line = line[0 : line.index('#')]
+ line = line[line.index('#')]
return line.split()
# now put every bracketed line in a test
@@ -127,4 +128,4 @@ class BlackList(object):
# found a match!
return line
else:
- return None # nothing found
+ return None # nothing found
diff --git a/testing/buildlog.py b/testing/buildlog.py
index 7160a6af9..d9e960418 100644
--- a/testing/buildlog.py
+++ b/testing/buildlog.py
@@ -121,7 +121,7 @@ class BuildLog(object):
lst.append(log_dir)
if lst:
def warn_problem(func, path, exc_info):
- cls, ins, tb = exc_info
+ cls, ins, _ = exc_info
print("rmtree({}) warning: problem with {}:\n {}: {}".format(
func.__name__, path,
cls.__name__, ins.args))
@@ -137,7 +137,7 @@ class BuildLog(object):
shutil.rmtree(log_dir, onerror=warn_problem)
def set_buildno(self, buildno):
- self.history[buildno] # test
+ self.history[buildno] # test
self._buildno = buildno
@property
@@ -174,4 +174,5 @@ class BuildLog(object):
res.append(key)
return res
+
builds = BuildLog()
diff --git a/testing/command.py b/testing/command.py
index 1279bb323..499ecaab7 100644
--- a/testing/command.py
+++ b/testing/command.py
@@ -89,9 +89,10 @@ COIN_THRESHOLD = 3 # report error if >=
COIN_TESTING = 5 # number of runs
if (os.environ.get("COIN_RERUN_FAILED_ONLY", "1").lower() in
- "0 f false n no".split()):
+ "0 f false n no".split()):
COIN_RERUN_FAILED_ONLY = False
+
def test_project(project, args, blacklist, runs):
ret = []
@@ -102,6 +103,7 @@ def test_project(project, args, blacklist, runs):
if os.path.exists(runner.logfile) and not args.skip:
os.unlink(runner.logfile)
# now start the real run
+ rerun_list = None
for idx in range(runs):
index = idx + 1
runner = TestRunner(builds.selected, project, index)
@@ -133,7 +135,7 @@ def test_project(project, args, blacklist, runs):
print(f"RES {index}: Test {sharp:>4}: {res:<6} {mod_name}()")
r[0] += 1 if res == "PASS" else 0
r[1] += 1 if res == "FAIL!" else 0
- r[2] += 1 if res == "SKIPPED" else 0 # not yet supported
+ r[2] += 1 if res == "SKIPPED" else 0 # not yet supported
r[3] += 1 if res == "BFAIL" else 0
r[4] += 1 if res == "BPASS" else 0
if res not in ("PASS", "BPASS"):
@@ -155,6 +157,7 @@ def test_project(project, args, blacklist, runs):
break
return ret, fatal
+
def main():
# create the top-level command parser
start_time = timer()
@@ -180,22 +183,21 @@ def main():
default=blacklist_default,
help='a Qt blacklist file (default: {})'.format(blacklist_default))
parser_test.add_argument("--skip", action='store_true',
- help="skip the tests if they were run before")
+ help="skip the tests if they were run before")
parser_test.add_argument("--environ", nargs='+',
- help="use name=value ... to set environment variables")
+ help="use name=value ... to set environment variables")
parser_test.add_argument("--buildno", default=-1, type=int,
- help="use build number n (0-based), latest = -1 (default)")
+ help="use build number n (0-based), latest = -1 (default)")
parser_test.add_argument("--projects", nargs='+', type=str,
- default=tested_projects,
- choices=all_projects,
- help="use '{}'' (default) or other projects"
- .format("' '".join(tested_projects)))
+ default=tested_projects,
+ choices=all_projects,
+ help="use '{}'' (default) or other projects"
+ .format("' '".join(tested_projects)))
parser_getcwd = subparsers.add_parser("getcwd")
parser_getcwd.add_argument("filename", type=argparse.FileType('w'),
- help="write the build dir name into a file")
+ help="write the build dir name into a file")
parser_getcwd.add_argument("--buildno", default=-1, type=int,
- help="use build number n (0-based), latest = -1 (default)")
- parser_list = subparsers.add_parser("list")
+ help="use build number n (0-based), latest = -1 (default)")
args = parser.parse_args()
if hasattr(args, "buildno"):
@@ -210,7 +212,7 @@ def main():
print(builds.selected.build_dir, "written to file", args.filename.name)
sys.exit(0)
elif args.subparser_name == "test":
- pass # we do it afterwards
+ pass # we do it afterwards
elif args.subparser_name == "list":
rp = os.path.relpath
print()
@@ -245,8 +247,8 @@ def main():
Version={version_lf}
API version={api_version}
- Environment:""")
- .format(version_lf=sys.version.replace("\n", " "), **sys.__dict__))
+ Environment:""").format(version_lf=sys.version.replace("\n", " "),
+ **sys.__dict__))
for key, value in sorted(os.environ.items()):
print(" {}={}".format(key, value))
print()
@@ -262,7 +264,7 @@ def main():
if fatal:
runs = 1
for idx, r in enumerate(res):
- q = list(map(lambda x, y: x+y, r, q))
+ q = list(map(lambda x, y: x + y, r, q))
if len(args.projects) > 1:
print("All above projects:", sum(q), "tests.",
@@ -332,7 +334,7 @@ def main():
# nag us about unsupported projects
ap, tp = set(all_projects), set(tested_projects)
if ap != tp:
- print("+++++ Note: please support", " ".join(ap-tp), "+++++")
+ print("+++++ Note: please support", " ".join(ap - tp), "+++++")
print()
stop_time = timer()
diff --git a/testing/helper.py b/testing/helper.py
index d192cf061..a8d3a65ff 100644
--- a/testing/helper.py
+++ b/testing/helper.py
@@ -44,26 +44,18 @@ Some tools that do not fit elsewhere.
"""
import os
-import sys
-from collections import namedtuple
-
-from subprocess import PIPE
-from subprocess import TimeoutExpired
-from io import StringIO
script_dir = os.path.dirname(os.path.dirname(__file__))
+
def decorate(mod_name):
"""
Write the combination of "modulename_funcname"
in the Qt-like form "modulename::funcname"
"""
- if "_" not in mod_name:
+ if "_" not in mod_name or "::" in mod_name:
return mod_name
- if "::" in mod_name:
- return mod_name
- name, rest = mod_name.split("_", 1)
- return name + "::" + rest
-
-#eof
+ else:
+ name, rest = mod_name.split("_", 1)
+ return f"{name}::{rest}"
diff --git a/testing/parser.py b/testing/parser.py
index 511facfed..16b3362c8 100644
--- a/testing/parser.py
+++ b/testing/parser.py
@@ -40,7 +40,7 @@
import os
import re
from collections import namedtuple
-from .helper import StringIO
+from io import StringIO
"""
testing/parser.py
@@ -105,6 +105,7 @@ assert len(re.match(_TEST_PAT, _EXAMPLE.splitlines()[7], re.VERBOSE).groups()) =
TestResult = namedtuple("TestResult", "idx n sharp mod_name passed "
"code time fatal rich_result".split())
+
def _parse_tests(test_log):
"""
Create a TestResult object for every entry.
@@ -124,7 +125,7 @@ def _parse_tests(test_log):
match = re.match(pat, line, re.VERBOSE)
if match and line.split()[-1] != "sec":
# don't change the number of lines
- lines[idx : idx + 2] = [line.rstrip() + lines[idx + 1], ""]
+ lines[idx:idx + 2] = [line.rstrip() + lines[idx + 1], ""]
pat = _TEST_PAT
for line in lines:
diff --git a/testing/runner.py b/testing/runner.py
index 09b873d26..084ca60ec 100644
--- a/testing/runner.py
+++ b/testing/runner.py
@@ -43,11 +43,8 @@ import re
import subprocess
import inspect
-from collections import namedtuple
from textwrap import dedent
-
-from .buildlog import builds
-from .helper import decorate, TimeoutExpired
+from subprocess import TimeoutExpired
# Get the dir path to the utils module
try:
@@ -61,6 +58,7 @@ build_scripts_dir = os.path.abspath(os.path.join(this_dir, '../build_scripts'))
sys.path.append(build_scripts_dir)
from utils import detect_clang
+
class TestRunner(object):
def __init__(self, log_entry, project, index):
self.log_entry = log_entry
@@ -82,7 +80,7 @@ class TestRunner(object):
if clang_dir[0]:
clang_bin_dir = os.path.join(clang_dir[0], 'bin')
path = os.environ.get('PATH')
- if not clang_bin_dir in path:
+ if clang_bin_dir not in path:
os.environ['PATH'] = clang_bin_dir + os.pathsep + path
print("Adding %s as detected by %s to PATH" % (clang_bin_dir, clang_dir[1]))
@@ -161,6 +159,7 @@ class TestRunner(object):
cwd=self.test_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
+
def py_tee(input, output, label):
'''
A simple (incomplete) tee command in Python
@@ -208,12 +207,12 @@ class TestRunner(object):
stdin=ctest_process.stdout)
try:
comm = tee_process.communicate
- output = comm(timeout=timeout)[0]
+ _ = comm(timeout=timeout)[0]
except (TimeoutExpired, KeyboardInterrupt):
print()
print("aborted, partial result")
ctest_process.kill()
- outs, errs = ctest_process.communicate()
+ _ = ctest_process.communicate()
# ctest lists to a temp file. Move it to the log
tmp_name = self.logfile + ".tmp"
if os.path.exists(tmp_name):
@@ -237,4 +236,3 @@ class TestRunner(object):
words = "^(" + "|".join(rerun) + ")$"
cmd += ("--tests-regex", words)
self._run(cmd, label, timeout)
-# eof
diff --git a/testing/wheel_tester.py b/testing/wheel_tester.py
index a8760d27c..90dff5ef4 100644
--- a/testing/wheel_tester.py
+++ b/testing/wheel_tester.py
@@ -53,7 +53,8 @@ directory (e.g. setup.py bdist_wheel was already executed).
"""
from argparse import ArgumentParser, RawTextHelpFormatter
-import os, sys
+import os
+import sys
try:
this_file = __file__
@@ -202,7 +203,7 @@ def raise_error_pyinstaller(msg):
print(f"PYINST: {msg}")
print(f"PYINST: sys.version = {sys.version.splitlines()[0]}")
print(f"PYINST: platform.platform() = {platform.platform()}")
- print(f"PYINST: See the error message above.")
+ print("PYINST: See the error message above.")
print()
for line in run_process_output([sys.executable, "-m", "pip", "list"]):
print(f"PyInstaller pip list: {line}")
@@ -211,13 +212,13 @@ def raise_error_pyinstaller(msg):
def compile_using_pyinstaller():
- src_path = os.path.join("..", "hello.py")
+ _ = os.path.join("..", "hello.py")
spec_path = os.path.join("..", "hello_app.spec")
exit_code = run_process([sys.executable, "-m", "PyInstaller", spec_path])
- # to create the spec file, this setting was used:
- #"--name=hello_app", "--console", "--log-level=DEBUG", src_path])
- # By using a spec file, we avoid all the probing that might disturb certain
- # platforms and also save some analysis time.
+ # to create the spec file, this setting was used:
+ # "--name=hello_app", "--console", "--log-level=DEBUG", src_path])
+ # By using a spec file, we avoid all the probing that might disturb certain
+ # platforms and also save some analysis time.
if exit_code:
# 2019-04-28 Raising on error is again enabled
raise_error_pyinstaller("Failure while compiling script using PyInstaller.")
@@ -296,7 +297,7 @@ def try_build_examples():
compile_using_pyinstaller()
run_compiled_script(os.path.join(src_path,
- "pyinstaller", "dist", "hello_app", "hello_app"))
+ "pyinstaller", "dist", "hello_app", "hello_app"))
log.info("Attempting to build and run samplebinding using cmake.")
src_path = os.path.join(examples_dir, "samplebinding")
@@ -335,7 +336,7 @@ def run_wheel_tests(install_wheels):
if __name__ == "__main__":
parser = ArgumentParser(description="wheel_tester",
- formatter_class=RawTextHelpFormatter)
+ formatter_class=RawTextHelpFormatter)
parser.add_argument('--no-install-wheels', '-n', action='store_true',
help='Do not install wheels'
' (for developer builds with virtualenv)')