diff options
author | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2021-07-12 10:39:42 +0200 |
---|---|---|
committer | Cristián Maureira-Fredes <Cristian.Maureira-Fredes@qt.io> | 2021-07-20 16:56:48 +0200 |
commit | 2654740274986e897427caf667fed93601e01bbd (patch) | |
tree | 436d1c4ac49755a18256f57e76f98977fd61eb0e /testing | |
parent | cd2c32050705d25e648bf8e015b3a1adf4134b05 (diff) |
testing: code styling with black
Addressing the long lines, and inconsistencies with double
and single quotes.
Pick-to: 6.1
Change-Id: I2d18116f0dd9215fa3cfe15482e606fc064f42da
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'testing')
-rw-r--r-- | testing/blacklist.py | 6 | ||||
-rw-r--r-- | testing/buildlog.py | 32 | ||||
-rw-r--r-- | testing/command.py | 96 | ||||
-rw-r--r-- | testing/parser.py | 18 | ||||
-rw-r--r-- | testing/runner.py | 45 | ||||
-rw-r--r-- | testing/wheel_tester.py | 51 |
6 files changed, 153 insertions, 95 deletions
diff --git a/testing/blacklist.py b/testing/blacklist.py index 3de29ce05..09848dce4 100644 --- a/testing/blacklist.py +++ b/testing/blacklist.py @@ -62,8 +62,8 @@ class BlackList(object): lines = self.raw_data[:] def filtered_line(line): - if '#' in line: - line = line[line.index('#')] + if "#" in line: + line = line[line.index("#")] return line.split() # now put every bracketed line in a test @@ -85,7 +85,7 @@ class BlackList(object): if is_test(fline): break # we have a global section - name = '' + name = "" self.tests[name] = [] for idx, line in enumerate(lines): fline = filtered_line(line) diff --git a/testing/buildlog.py b/testing/buildlog.py index 4e41cbaf5..d268c1ac3 100644 --- a/testing/buildlog.py +++ b/testing/buildlog.py @@ -65,14 +65,15 @@ class BuildLog(object): For simplicity and readability, the log entries are named tuples. """ + def __init__(self): - history_dir = os.path.join(script_dir, 'build_history') + history_dir = os.path.join(script_dir, "build_history") build_history = [] for timestamp in os.listdir(history_dir): log_dir = os.path.join(history_dir, timestamp) if not os.path.isdir(log_dir): continue - fpath = os.path.join(log_dir, 'build_dir.txt') + fpath = os.path.join(log_dir, "build_dir.txt") if not os.path.exists(fpath): continue with open(fpath) as f: @@ -86,10 +87,14 @@ class BuildLog(object): build_dir = f_contents_split[0] build_classifiers = "" except IndexError: - print(dedent(f""" + print( + dedent( + f""" Error: There was an issue finding the build dir and its characteristics, in the following considered file: '{fpath}' - """)) + """ + ) + ) sys.exit(1) if not os.path.exists(build_dir): @@ -120,10 +125,13 @@ class BuildLog(object): continue lst.append(log_dir) if lst: + def warn_problem(func, path, exc_info): cls, ins, _ = exc_info - print(f"rmtree({func.__name__}) warning: problem with " - f"{path}:\n {cls.__name__}: {ins.args}") + print( + f"rmtree({func.__name__}) warning: problem with " + f"{path}:\n {cls.__name__}: {ins.args}" + ) lst.sort() log_dir = lst[-1] @@ -150,20 +158,20 @@ class BuildLog(object): @property def classifiers(self): if not self.selected: - raise ValueError('+++ No build with the configuration found!') + raise ValueError("+++ No build with the configuration found!") # Python2 legacy: Correct 'linux2' to 'linux', recommended way. - platform = 'linux' if sys.platform.startswith('linux') else sys.platform - res = [platform, 'qt6'] + platform = "linux" if sys.platform.startswith("linux") else sys.platform + res = [platform, "qt6"] if is_ci: - res.append('ci') + res.append("ci") if self.selected.build_classifiers: # Use classifier string encoded into build_dir.txt file. - res.extend(self.selected.build_classifiers.split('-')) + res.extend(self.selected.build_classifiers.split("-")) else: # the rest must be guessed from the given filename path = self.selected.build_dir base = os.path.basename(path) - res.extend(base.split('-')) + res.extend(base.split("-")) # add all the python and qt subkeys for entry in res: parts = entry.split(".") diff --git a/testing/command.py b/testing/command.py index 5c4f58eca..307a59761 100644 --- a/testing/command.py +++ b/testing/command.py @@ -85,11 +85,10 @@ from .parser import TestParser # Should we repeat only failed tests? COIN_RERUN_FAILED_ONLY = True -COIN_THRESHOLD = 3 # report error if >= -COIN_TESTING = 5 # number of runs +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()): +if os.environ.get("COIN_RERUN_FAILED_ONLY", "1").lower() in "0 f false n no".split(): COIN_RERUN_FAILED_ONLY = False @@ -143,8 +142,10 @@ def test_project(project, args, blacklist, runs): if item.fatal: fatal = item print() - print(f"Totals: {sum(r)} tests. " - f"{r[0]} passed, {r[1]} failed, {r[2]} skipped, {r[3]} blacklisted, {r[4]} bpassed.") + print( + f"Totals: {sum(r)} tests. " + f"{r[0]} passed, {r[1]} failed, {r[2]} skipped, {r[3]} blacklisted, {r[4]} bpassed." + ) print() print(f"********* Finished testing of {project} *********") print() @@ -164,38 +165,60 @@ def main(): tested_projects_quoted = " ".join("'i'" for i in tested_projects) parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, - description=dedent("""\ + description=dedent( + """\ Run the tests for some projects, default = {tested_projects_quoted}. Testing is now repeated up to {COIN_TESTING} times, and errors are only reported if they occur {COIN_THRESHOLD} or more times. The environment variable COIN_RERUN_FAILED_ONLY controls if errors are only repeated if there are errors. The default is "1". - """)) + """ + ), + ) subparsers = parser.add_subparsers(dest="subparser_name") # create the parser for the "test" command parser_test = subparsers.add_parser("test") group = parser_test.add_mutually_exclusive_group(required=False) - blacklist_default = os.path.join(script_dir, 'build_history', 'blacklist.txt') - group.add_argument("--blacklist", "-b", type=argparse.FileType('r'), - default=blacklist_default, - help=f'a Qt blacklist file (default: {blacklist_default})') - parser_test.add_argument("--skip", action='store_true', - help="skip the tests if they were run before") - parser_test.add_argument("--environ", nargs='+', - 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)") - parser_test.add_argument("--projects", nargs='+', type=str, - default=tested_projects, - choices=all_projects, - help=f"use {tested_projects_quoted} (default) or other projects") + blacklist_default = os.path.join(script_dir, "build_history", "blacklist.txt") + group.add_argument( + "--blacklist", + "-b", + type=argparse.FileType("r"), + default=blacklist_default, + help=f"a Qt blacklist file (default: {blacklist_default})", + ) + parser_test.add_argument( + "--skip", action="store_true", help="skip the tests if they were run before" + ) + parser_test.add_argument( + "--environ", nargs="+", 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)", + ) + parser_test.add_argument( + "--projects", + nargs="+", + type=str, + default=tested_projects, + choices=all_projects, + help=f"use {tested_projects_quoted} (default) or other 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") - parser_getcwd.add_argument("--buildno", default=-1, type=int, - help="use build number n (0-based), latest = -1 (default)") + parser_getcwd.add_argument( + "filename", type=argparse.FileType("w"), 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)", + ) args = parser.parse_args() if hasattr(args, "buildno"): @@ -238,14 +261,18 @@ def main(): key, value = things os.environ[key] = value - print(dedent("""\ + print( + dedent( + """\ System: Platform={sys.__dict__["platform"]} Executable={sys.__dict__["executable"]} Version={sys.version.replace("\n", " ")} API version={sys.__dict__["api_version"]} - Environment:""")) + Environment:""" + ) + ) for key, value in sorted(os.environ.items()): print(f" {key}={value}") print() @@ -264,8 +291,10 @@ def main(): q = list(map(lambda x, y: x + y, r, q)) if len(args.projects) > 1: - print(f"All above projects: {sum(q)} tests. " - f"{q[0]} passed, {q[1]} failed, {q[2]} skipped, {q[3]} blacklisted, {q[4]} bpassed.") + print( + f"All above projects: {sum(q)} tests. " + f"{q[0]} passed, {q[1]} failed, {q[2]} skipped, {q[3]} blacklisted, {q[4]} bpassed." + ) print() tot_res = OrderedDict() @@ -347,11 +376,14 @@ def main(): if fail_count == 1: raise ValueError(f"A test was not blacklisted and met the criterion {err_crit}") elif fail_count > 1: - raise ValueError(f"{fail_count} failures were not blacklisted " - f"and met the criterion {err_crit}") + raise ValueError( + f"{fail_count} failures were not blacklisted " f"and met the criterion {err_crit}" + ) print(f"No test met the error criterion {err_crit}") finally: print() print(f"Total time of whole Python script = {used_time:0.2f} sec") print() + + # eof diff --git a/testing/parser.py b/testing/parser.py index 76f1f34b2..7e1e6c792 100644 --- a/testing/parser.py +++ b/testing/parser.py @@ -80,7 +80,9 @@ _TEST_PAT_PRE = r""" ([0-9]+) # sharp : # colon symbol ':' """ -_TEST_PAT = _TEST_PAT_PRE + r""" +_TEST_PAT = ( + _TEST_PAT_PRE + + r""" \s+ # some WS ([\w-]+) # mod_name .*? # whatever (non greedy) @@ -96,14 +98,16 @@ _TEST_PAT = _TEST_PAT_PRE + r""" \s* # any WS $ # end """ +) # validation of our pattern: assert re.match(_TEST_PAT, _EXAMPLE.splitlines()[5], re.VERBOSE) assert len(re.match(_TEST_PAT, _EXAMPLE.splitlines()[5], re.VERBOSE).groups()) == 8 assert len(re.match(_TEST_PAT, _EXAMPLE.splitlines()[7], re.VERBOSE).groups()) == 8 -TestResult = namedtuple("TestResult", "idx n sharp mod_name passed " - "code time fatal rich_result".split()) +TestResult = namedtuple( + "TestResult", "idx n sharp mod_name passed " "code time fatal rich_result".split() +) def _parse_tests(test_log): @@ -125,7 +129,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: @@ -145,9 +149,9 @@ def _parse_tests(test_log): if idx + 1 != item.idx: # The numbering is disrupted. Provoke an error in this line! code = f"{code}, but lines are disrupted!" - result[idx] = item._replace(passed=False, - code=f"{item.code}, but lines are disrupted!", - fatal=True) + result[idx] = item._replace( + passed=False, code=f"{item.code}, but lines are disrupted!", fatal=True + ) break return result diff --git a/testing/runner.py b/testing/runner.py index 2623b7937..50c08d21d 100644 --- a/testing/runner.py +++ b/testing/runner.py @@ -53,7 +53,7 @@ except NameError: this_file = sys.argv[0] this_file = os.path.abspath(this_file) this_dir = os.path.dirname(this_file) -build_scripts_dir = os.path.abspath(os.path.join(this_dir, '../build_scripts')) +build_scripts_dir = os.path.abspath(os.path.join(this_dir, "../build_scripts")) sys.path.append(build_scripts_dir) from utils import detect_clang @@ -69,7 +69,7 @@ class TestRunner(object): self.logfile = os.path.join(log_dir, f"{project}.{index}.log") else: self.logfile = os.path.join(log_dir, f"{project}.log") - os.environ['CTEST_OUTPUT_ON_FAILURE'] = '1' + os.environ["CTEST_OUTPUT_ON_FAILURE"] = "1" self._setup_clang() self._setup() @@ -78,10 +78,10 @@ class TestRunner(object): return clang_dir = detect_clang() if clang_dir[0]: - clang_bin_dir = os.path.join(clang_dir[0], 'bin') - path = os.environ.get('PATH') + clang_bin_dir = os.path.join(clang_dir[0], "bin") + path = os.environ.get("PATH") if clang_bin_dir not in path: - os.environ['PATH'] = clang_bin_dir + os.pathsep + path + os.environ["PATH"] = clang_bin_dir + os.pathsep + path print(f"Adding {clang_bin_dir} as detected by {clang_dir[1]} to PATH") def _find_ctest_in_file(self, file_name): @@ -99,11 +99,13 @@ class TestRunner(object): # We have probably forgotten to build the tests. # Give a nice error message with a shortened but exact path. rel_path = os.path.relpath(file_name) - msg = dedent(f"""\n + msg = dedent( + f"""\n {'*' * 79} ** ctest is not in '{rel_path}'. * Did you forget to build the tests with '--build-tests' in setup.py? - """) + """ + ) raise RuntimeError(msg) # the ctest program is on the left to look_for assert line, f"Did not find {look_for}" @@ -126,8 +128,9 @@ class TestRunner(object): path = os.path.join(self.test_dir, candidate) if os.path.exists(path): return self._find_ctest_in_file(path) - raise RuntimeError("Cannot find any of the build system files " - f"{', '.join(candidate_files)}.") + raise RuntimeError( + "Cannot find any of the build system files " f"{', '.join(candidate_files)}." + ) def _setup(self): self.ctestCommand = self._find_ctest() @@ -151,17 +154,20 @@ class TestRunner(object): # without a caret are interpreted as such which leads to weirdness. # Since we have all commands with explicit paths and don't use shell # commands, this should work fine. - print(dedent(f"""\ + print( + dedent( + f"""\ running {self.cmd} in {self.test_dir} - """)) - ctest_process = subprocess.Popen(self.cmd, - cwd=self.test_dir, - stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) + """ + ) + ) + ctest_process = subprocess.Popen( + self.cmd, cwd=self.test_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) def py_tee(input, output, label): - ''' + """ A simple (incomplete) tee command in Python This script simply logs everything from input to output @@ -176,7 +182,8 @@ class TestRunner(object): The special escape is for the case of an embedded file in the output. - ''' + """ + def xprint(*args, **kw): print(*args, file=output, **kw) @@ -199,9 +206,7 @@ class TestRunner(object): tee_src = dedent(inspect.getsource(py_tee)) tee_src = f"import sys\n{tee_src}\npy_tee(sys.stdin, sys.stdout, '{label}')" tee_cmd = (sys.executable, "-E", "-u", "-c", tee_src) - tee_process = subprocess.Popen(tee_cmd, - cwd=self.test_dir, - stdin=ctest_process.stdout) + tee_process = subprocess.Popen(tee_cmd, cwd=self.test_dir, stdin=ctest_process.stdout) try: comm = tee_process.communicate _ = comm(timeout=timeout)[0] diff --git a/testing/wheel_tester.py b/testing/wheel_tester.py index 4705fcdee..567d2380e 100644 --- a/testing/wheel_tester.py +++ b/testing/wheel_tester.py @@ -64,7 +64,7 @@ except NameError: this_file = sys.argv[0] this_file = os.path.abspath(this_file) this_dir = os.path.dirname(this_file) -setup_script_dir = os.path.abspath(os.path.join(this_dir, '..')) +setup_script_dir = os.path.abspath(os.path.join(this_dir, "..")) sys.path.append(setup_script_dir) from build_scripts.utils import find_files_using_glob @@ -90,8 +90,9 @@ def find_executable(executable, command_line_value): paths = find_glob_in_path(executable) log.info(f"{executable} executables found in PATH: {paths}") if not paths: - raise RuntimeError(f"No {option_str} option was specified and no {executable} was " - "found in PATH.") + raise RuntimeError( + f"No {option_str} option was specified and no {executable} was " "found in PATH." + ) else: value = paths[0] log.info(f"Using {executable} found in PATH: {value}") @@ -161,8 +162,9 @@ def try_install_wheels(wheels_dir, py_version): elif len(files) > 1: raise RuntimeError(f"More than one wheel found for specific {p} version.") else: - raise RuntimeError(f"No {p} wheels compatible with Python {py_version} found " - f"for testing.") + raise RuntimeError( + f"No {p} wheels compatible with Python {py_version} found " f"for testing." + ) def is_unix(): @@ -209,7 +211,7 @@ def raise_error_pyinstaller(msg): for line in run_process_output([sys.executable, "-m", "pip", "list"]): print(f"PyInstaller pip list: {line}") print() - raise(RuntimeError(msg)) + raise (RuntimeError(msg)) def compile_using_pyinstaller(): @@ -324,8 +326,7 @@ def try_build_examples(): src_path = os.path.join(examples_dir, "installer_test") prepare_build_folder(src_path, "pyinstaller") compile_using_pyinstaller() - run_compiled_script(os.path.join(src_path, - "pyinstaller", "dist", "hello_app", "hello_app")) + run_compiled_script(os.path.join(src_path, "pyinstaller", "dist", "hello_app", "hello_app")) log.info("Attempting to build hello.py using Nuitka.") src_path = Path(examples_dir) / "installer_test" @@ -359,9 +360,17 @@ def try_build_examples(): with tempfile.TemporaryDirectory() as tmpdirname: src_path = Path(tmpdirname) / "pyi_test" pyi_script_dir = Path(setup_script_dir) / "sources" / "pyside6" / "PySide6" / "support" - execute_script(pyi_script_dir / "generate_pyi.py", "all", "--outpath", src_path, - "--feature", "snake_case", "true_property") + execute_script( + pyi_script_dir / "generate_pyi.py", + "all", + "--outpath", + src_path, + "--feature", + "snake_case", + "true_property", + ) from PySide6 import __all__ as modules + for modname in modules: execute_script(src_path / f"{modname}.pyi") @@ -381,17 +390,17 @@ def run_wheel_tests(install_wheels): if __name__ == "__main__": - parser = ArgumentParser(description="wheel_tester", - formatter_class=RawTextHelpFormatter) - parser.add_argument('--no-install-wheels', '-n', action='store_true', - help='Do not install wheels' - ' (for developer builds with virtualenv)') - parser.add_argument("--qmake", type=str, - help="Path to qmake") - parser.add_argument("--cmake", type=str, - help="Path to cmake") + parser = ArgumentParser(description="wheel_tester", formatter_class=RawTextHelpFormatter) + parser.add_argument( + "--no-install-wheels", + "-n", + action="store_true", + help="Do not install wheels" " (for developer builds with virtualenv)", + ) + parser.add_argument("--qmake", type=str, help="Path to qmake") + parser.add_argument("--cmake", type=str, help="Path to cmake") options = parser.parse_args() - QMAKE_PATH = find_executable('qmake', options.qmake) - CMAKE_PATH = find_executable('cmake', options.cmake) + QMAKE_PATH = find_executable("qmake", options.qmake) + CMAKE_PATH = find_executable("cmake", options.cmake) run_wheel_tests(not options.no_install_wheels) |