From 7b077777810521200b84fdd142107cd18d00e3e4 Mon Sep 17 00:00:00 2001 From: Adam Blank <blank@caltech.edu> Date: Sat, 19 Oct 2024 00:25:24 +0000 Subject: [PATCH] Add new file --- test.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test.py diff --git a/test.py b/test.py new file mode 100644 index 0000000..5703a3f --- /dev/null +++ b/test.py @@ -0,0 +1,57 @@ +import pytest +import os +from io import StringIO +import sys +import re + + +def clear(): + """ + Clears the terminal screen. + """ + print("\033c", end="", flush=True) + + +clear() + +for f in sorted(set(os.listdir('tests')) - set(['__pycache__', '__init__.py', 'helpers'])): + print(f.split(".")[-1] + " Tests: ") + for t in sorted(set(os.listdir(os.path.join('tests/' + f))) - set(['__pycache__'])): + sys.stdout = result = StringIO() + code = pytest.main(["-vv", "--color=yes", "--no-header", "--disable-warnings", "-rNs", "-x"] + + [os.path.join('tests', f, t)], ['pytest_clarity']) + sys.stdout = sys.__stdout__ + if code == 0: + print(" " + + "\x1b[0m\x1b[32mPASSED\x1b[0m " + t.replace(".py", "")) + continue + + before = 0 + skip = 0 + i = 0 + lines = result.getvalue().splitlines()[3:] + while i < len(lines): + line = lines[i].replace("LHS", "CORRECT").replace( + "RHS", "YOURS").replace("[pytest-clarity diff shown]", "") + if 'collecting' in line or '================' in line or '!!!!!!!' in line: + i += 1 + continue + if '@pytest' in line: + before = 1 + if line.startswith("------"): + line = line[4:-4] + if line.startswith(os.path.join('tests', f, t)): + line = line.replace(os.path.join( + 'tests', f, t) + "::", "") + if "PASSED" not in line: + i += 5 + if line.startswith('\x1b[1m\x1b[31mE '): + before = 2 + + if before < 1 or before > 1: + print(' ' + line) + + i += 1 + if code != 0: + exit(1) + print() -- GitLab