Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/test_progress_dashboard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""tools/progress_dashboard.py: parsers, classification, the no-game-data rule and the output-folder rule.

python -I tests/test_progress_dashboard.py
Expand Down Expand Up @@ -517,6 +517,34 @@
self.assertEqual(pd.scrub("in " + os.path.join(pd.HOME, "work", f"{SENTINEL}.fssm")), "in <path>")
self.assertEqual(pd.scrub(f"C:{sep}work{sep}{SENTINEL}_a.fssm, C:{sep}{SENTINEL}_b.fssm"), "<path> <path>")

def test_drive_paths_with_spaces_lose_their_whole_name(self):
for line, want in (
(rf"FAIL: cannot read D:\My work\shaders\{SENTINEL}.fssm", "FAIL: cannot read <path>"),
(rf"D:\My work\a b c\{SENTINEL}.fssm line 3", "<path> line 3"),
(rf"D:\My work\{SENTINEL}_a.fssm, D:\Other work\{SENTINEL}_b.fssm", "<path> <path>"),
(f"FAIL: cannot read D:/My work/shaders/{SENTINEL}.fssm", "FAIL: cannot read <path>"),
(rf"cannot read D:/My work\fixtures\{SENTINEL}.txt", "cannot read <path>"),
(rf"cannot read D:\My work/stubs/{SENTINEL}.spv", "cannot read <path>"),
(rf"D:\My own work/sub dir\a b/{SENTINEL}.fssm line 3", "<path> line 3"),
(rf"D:\My work/{SENTINEL}_a.fssm, D:/Other work\{SENTINEL}_b.fssm", "<path> <path>"),
(rf"Permission denied: 'D:\\My work\\{SENTINEL} one.fssm'", "Permission denied: '<path>'"),
(rf'File "D:\My work\{SENTINEL} one.py", line 3', 'File "<path>", line 3'),
(r"D:\work\a.txt is not a folder", "<path> is not a folder"),
(r"D:\work\a.txt, then tests/test_x.py failed", "<path> then tests/test_x.py failed"),
(r"D:\work\a.txt and tests/test_x.py failed", "<path> and tests/test_x.py failed"),
(r"D:\work\a.txt is 3/4 done", "<path> is 3/4 done"),
# The same separator, after a file name: the prose stays too.
("D:/work/a.txt and tests/test_x.py failed", "<path> and tests/test_x.py failed"),
(r"D:\work\a.txt and tests\test_x.py failed", r"<path> and tests\test_x.py failed"),
("D:/work/a.txt is 3/4 done", "<path> is 3/4 done"),
(f"D:/My work/Python 3.12 x/{SENTINEL}.fssm line 3", "<path> line 3"),
):
with self.subTest(line=line):
self.assertEqual(pd.scrub(line), want)
if os.name == "nt":
sibling = os.path.join(ROOT + " work", f"{SENTINEL} one.fssm")
self.assertEqual(pd.scrub(f"cannot read '{sibling}' now"), "cannot read '<path>' now")

def test_paths_inside_the_repository_become_relative(self):
line = "Error: " + os.path.join(ROOT, "tools", "text_tables.py") + " line 3"
self.assertEqual(pd.scrub(line), "Error: tools/text_tables.py line 3")
Expand Down
14 changes: 12 additions & 2 deletions tools/progress_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,19 @@ def shown(m):
checkout = rf"(?<![\w.:/~]){re.escape(ROOT)}"
# Consume a same-prefix sibling too, so shown() can redact its entire path.
checkout_path = rf"{checkout}[^\s'\"]*"
drive_path = r"(?i:\b[a-z]:[\\/][^\s'\"]*)"
# A quoted drive path ends at its quote. An unquoted one goes on over spaces while a later part still has its
# separator, so `D:\My work\name` is one path, but only after a part with no dot or punctuation: the prose after
# a file name stays, slashes included (`D:/work/a.txt and tests/test_x.py`). The other separator continues it too
# (`D:/My work\name`), with no punctuation in the words before that part.
drive = r"\b[a-z]:"
quoted_path = rf"(?i:(?<='){drive}[\\/][^']*(?=')|(?<=\"){drive}[\\/][^\"]*(?=\"))"
folder = r"(?:[^\s'\"]*[\\/])?[^\s'\"\\/.,;:]*"
mixed = r"(?: +[^\s'\"\\/.,;:]+)*? +[^\s'\"\\/:]+[\\/]"
more = r"(?: +(?![a-z]:[\\/])[^\s'\"\\/]+)*? +(?![a-z]:[\\/])[^\s'\"\\/]+{sep}"
drive_path = "(?i:" + "|".join(rf"{drive}{sep}(?:{folder}(?:{mixed}|{more.format(sep=sep)}))*[^\s'\"]*"
for sep in (r"\\", "/")) + ")"
posix_path = r"(?<![\w.:/~])/[^\s/'\"][^\s'\"]*"
line = re.sub(rf"{checkout_path}|{drive_path}|{posix_path}", shown, line)
line = re.sub(rf"{quoted_path}|{checkout_path}|{drive_path}|{posix_path}", shown, line)
if HOME and len(HOME) > 3:
line = line.replace(HOME, "~")
line = re.sub(r"~[\\/][^\s'\"]*", "<path>", line)
Expand Down
Loading