diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd0018d779..9b19ef50ed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ exclude: configure|\.*.msh|\.*.rng|^h5hut/\.*|^libjudy\.*|^libmba2d\.*|^libmba3d\.*|^libspud\.*|^spatialindex-1.8.0\.* repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: check-ast - id: check-builtin-literals @@ -19,12 +19,12 @@ repos: - id: mixed-line-ending exclude: ref_vtk_hexahedra.vtu - id: trailing-whitespace -- repo: https://github.com/psf/black - rev: 23.3.0 +- repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.5.1 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 9.0.0b5 hooks: - id: isort args: ["--profile", "black", "--filter-files"] @@ -33,7 +33,7 @@ repos: hooks: - id: pyupgrade - repo: https://github.com/PyCQA/flake8 - rev: 6.1.0 + rev: 7.3.0 hooks: - id: flake8 args: ["--max-line-length", "88", "--extend-ignore", "E203,E722"] diff --git a/examples/driven_cavity/driven_cavity.py b/examples/driven_cavity/driven_cavity.py index 288d87a075..0ac4e5e7c2 100644 --- a/examples/driven_cavity/driven_cavity.py +++ b/examples/driven_cavity/driven_cavity.py @@ -160,7 +160,7 @@ def erturk_u(NN): ) velocity = u.ProbeData(pts, "Velocity") - (ilen, jlen) = velocity.shape + ilen, jlen = velocity.shape norm = 0.0 for i in range(ilen): diff = pts[i][3] - velocity[i][0] @@ -217,7 +217,7 @@ def erturk_v(NN): ) velocity = u.ProbeData(pts, "Velocity") - (ilen, jlen) = velocity.shape + ilen, jlen = velocity.shape norm = 0.0 for i in range(ilen): diff = pts[i][3] - velocity[i][1] @@ -269,7 +269,7 @@ def botella_u(NN): ) velocity = u.ProbeData(pts, "Velocity") - (ilen, jlen) = velocity.shape + ilen, jlen = velocity.shape norm = 0.0 for i in range(ilen): diff = pts[i][3] - velocity[i][0] @@ -320,7 +320,7 @@ def botella_v(NN): ) velocity = u.ProbeData(pts, "Velocity") - (ilen, jlen) = velocity.shape + ilen, jlen = velocity.shape norm = 0.0 for i in range(ilen): @@ -372,7 +372,7 @@ def botella_p1(NN): ) velocity = u.ProbeData(pts, "Velocity") - (ilen, jlen) = velocity.shape + ilen, jlen = velocity.shape pressure = u.ProbeData(pts, "Pressure") pts0 = np.array( @@ -430,7 +430,7 @@ def botella_p2(NN): ) velocity = u.ProbeData(pts, "Velocity") - (ilen, jlen) = velocity.shape + ilen, jlen = velocity.shape pressure = u.ProbeData(pts, "Pressure") pts0 = np.array( diff --git a/examples/driven_cavity/generate_mesh b/examples/driven_cavity/generate_mesh index 75bb3f77ef..83b13b9e94 100755 --- a/examples/driven_cavity/generate_mesh +++ b/examples/driven_cavity/generate_mesh @@ -12,7 +12,7 @@ optparser = OptionParser( description="""Generate the mesh files for a given resolution.""", ) -(options, argv) = optparser.parse_args() +options, argv = optparser.parse_args() try: NN = int(argv[0]) diff --git a/examples/driven_cavity/plot_data b/examples/driven_cavity/plot_data index ad5b8f12df..133fc74d11 100755 --- a/examples/driven_cavity/plot_data +++ b/examples/driven_cavity/plot_data @@ -7,11 +7,9 @@ import pylab def usage(): - print( - """plot_data + print("""plot_data - is a space-separated list of the inverse mesh spacing.""" - ) + is a space-separated list of the inverse mesh spacing.""") try: diff --git a/tools/unittestharness.py b/tools/unittestharness.py index 58078be5c1..3d45e3274b 100755 --- a/tools/unittestharness.py +++ b/tools/unittestharness.py @@ -34,12 +34,14 @@ def display_results(tests_results, error_list, skip_list): ) -def unittest_harness_no_output(tests): +def unittest_harness_no_output(tests, quiet=False): tests_results = {"Pass": Counter(), "Warn": Counter(), "Fail": Counter()} error_list, skip_list = [], [] + dot_count = 0 for test in tests: - print(f"\t-> New test: {test.name}") + if not quiet: + print(f"\t-> New test: {test.name}") if (tests_dir / test.name).is_file() is False: print(f"WARNING: {test.name} not found") @@ -64,25 +66,54 @@ def unittest_harness_no_output(tests): error_list.append(test.name) continue + non_pass_output = [] + has_failure = False for test_output in test_proc.stdout.splitlines(): try: tests_results[test_output[:4]][test.name] += 1 except KeyError: - print(f"\t\t\t{test_output.lstrip()}") + if not quiet: + print(f"\t\t\t{test_output.lstrip()}") continue - print(f"\t\t{test_output}") + if test_output[:4] in ("Warn", "Fail"): + has_failure = True + non_pass_output.append(test_output) + + if not quiet: + print(f"\t\t{test_output}") + + if quiet and has_failure: + if dot_count: + print() + dot_count = 0 + print(f"\t-> Failed test: {test.name}") + for output_line in non_pass_output: + print(f"\t\t{output_line}") + if test_proc.stderr: + print(f"\t\tStderr output: {test_proc.stderr}") + elif quiet: + print(".", end="", flush=True) + dot_count += 1 + if dot_count == 80: + print() + dot_count = 0 + + if quiet and dot_count: + print() display_results(tests_results, error_list, skip_list) -def unittest_harness(tests, xml_outfile): +def unittest_harness(tests, xml_outfile, quiet=False): xml_parser = TestSuite("unittest_harness") tests_results = {"Pass": Counter(), "Warn": Counter(), "Fail": Counter()} error_list, skip_list = [], [] + dot_count = 0 for test in tests: - print(f"\t-> New test: {test.name}") + if not quiet: + print(f"\t-> New test: {test.name}") if (tests_dir / test.name).is_file() is False: print(f"WARNING: {test.name} not found") @@ -125,15 +156,23 @@ def unittest_harness(tests, xml_outfile): continue other_out = "" + non_pass_output = [] + has_failure = False for test_output in test_proc.stdout.splitlines(): try: tests_results[test_output[:4]][test.name] += 1 except KeyError: - print(f"\t\t\t{test_output.lstrip()}") + if not quiet: + print(f"\t\t\t{test_output.lstrip()}") other_out += test_output.lstrip() + "\n" continue - print(f"\t\t{test_output}") + if test_output[:4] in ("Warn", "Fail"): + has_failure = True + non_pass_output.append(test_output) + + if not quiet: + print(f"\t\t{test_output}") try: # Look for the test output message enclosed between brackets @@ -172,6 +211,25 @@ def unittest_harness(tests, xml_outfile): xml_parser.test_cases.append(xml_entry) + if quiet and has_failure: + if dot_count: + print() + dot_count = 0 + print(f"\t-> Failed test: {test.name}") + for output_line in non_pass_output: + print(f"\t\t{output_line}") + if test_proc.stderr: + print(f"\t\tStderr output: {test_proc.stderr}") + elif quiet: + print(".", end="", flush=True) + dot_count += 1 + if dot_count == 80: + print() + dot_count = 0 + + if quiet and dot_count: + print() + display_results(tests_results, error_list, skip_list) with open(xml_outfile, "w") as fid: @@ -223,6 +281,12 @@ def add_path_to_environment_variable(env_var, env_path): help="remove the directory provided through --dir", ) parser.add_argument("--efence", action="store_true", help="links against libefence") +parser.add_argument( + "-q", + "--quiet", + action="store_true", + help="only print diagnostics for failing tests", +) args = parser.parse_args() fluidity_root = Path(sys.argv[0]).resolve().parent.parent @@ -261,6 +325,6 @@ def add_path_to_environment_variable(env_var, env_path): assert ( float(get_distribution("junit_xml").version) >= 1.9 ), "Please update junit_xml" - unittest_harness(tests, args.xml_output) + unittest_harness(tests, args.xml_output, args.quiet) else: - unittest_harness_no_output(tests) + unittest_harness_no_output(tests, args.quiet)