diff options
| author | user <user@clank> | 2026-08-17 14:36:59 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-17 14:36:59 +0200 |
| commit | c0022776d0912042819e4ea330cf7491a8196b45 (patch) | |
| tree | 3c5d547f273d8304e7cd6834fd5a2c730a495064 /tests/test_hints.py | |
| parent | sl0ppty: ruff formats the Python, and sorts its imports (diff) | |
| download | slosh-c0022776d0912042819e4ea330cf7491a8196b45.tar.gz slosh-c0022776d0912042819e4ea330cf7491a8196b45.tar.xz slosh-c0022776d0912042819e4ea330cf7491a8196b45.zip | |
sl0ppty: ruff format the Python
The bumpy one, again. Every `.py` outside `vendor/` plus the three `contrib/`
scripts that are Python with no extension: 60 files, 6,714 lines rewritten, no
behaviour changed. Nothing here is worth reading -- the next commit adds it to
`.git-blame-ignore-revs` so `git blame` walks past it.
It is a bigger reformat than the C was, 60% of the lines against 17%, and for a
reason worth writing down rather than tuning away: ruff and black break a call that
does not fit onto one argument per line, where this code aligned the continuation
under the opening paren. The test suite is thousands of `check("some prose", cond,
detail)` calls, so nearly every one of them changed shape and the suite grew 3,308
lines. Line length was the one lever that moved it -- 120 columns would have been a
40% reformat and no growth at all -- and it was left at 88, because picking an
unusual width to dodge a one-time diff is paying forever to avoid paying once.
Import sorting came with it. Two files had `import os, pty, uuid, select, struct,
sys, termios, time, fcntl, signal` on one line and now have ten.
Verified after, not before, because a formatter that alters behaviour would be
worse than none:
- `make retest`, 1801 checks green -- and this reformats the suite that does the
checking, including `harness.py`, which every one of those files imports.
- `make test-live`, the tty tests the fast suite skips. They matter here more than
usual: `live_input.py` and `live_m0.py` are two of the files whose comma-imports
were split, and nothing in the fast suite would have noticed if that broke them.
- All 60 files still compile, `make fmt` twice in a row changes nothing the second
time, and `ruff check --select I` has nothing left to say.
Diffstat (limited to 'tests/test_hints.py')
| -rw-r--r-- | tests/test_hints.py | 115 |
1 files changed, 73 insertions, 42 deletions
diff --git a/tests/test_hints.py b/tests/test_hints.py index bf00d87..fd85711 100644 --- a/tests/test_hints.py +++ b/tests/test_hints.py @@ -6,6 +6,7 @@ when clicked looks exactly like a border. The hint is read off the hit list rather than tracked, so anything that registers a hit gets one by being named in the table and nothing has to remember to raise it. """ + import os import sys import tempfile @@ -39,12 +40,17 @@ def test_each_button_says_what_it_does(): s.settle(20) s.api("split", dir="cols") s.settle(20) - check("nothing is said before the pointer is on anything", - "minimise" not in bar(s) and "close" not in bar(s), repr(bar(s))) + check( + "nothing is said before the pointer is on anything", + "minimise" not in bar(s) and "close" not in bar(s), + repr(bar(s)), + ) - for prefix, word in (("minimize:", "minimise"), - ("zoom:", "fill the tab"), - ("close:", "close this pane")): + for prefix, word in ( + ("minimize:", "minimise"), + ("zoom:", "fill the tab"), + ("close:", "close this pane"), + ): h = hit(s, prefix) hover(s, h["x"], h["y"]) check(f"{prefix[:-1]} says its word", word in bar(s), repr(bar(s))) @@ -61,10 +67,13 @@ def test_the_zoom_hint_says_which_way_it_goes(): s.send(r"\x01z") s.settle(20) - h = hit(s, "zoom:") # the button moved with the pane + h = hit(s, "zoom:") # the button moved with the pane hover(s, h["x"], h["y"]) - check("and to undo it once it is zoomed", - "back to the layout" in bar(s), repr(bar(s))) + check( + "and to undo it once it is zoomed", + "back to the layout" in bar(s), + repr(bar(s)), + ) def test_a_border_names_the_direction_it_would_split(): @@ -72,9 +81,10 @@ def test_a_border_names_the_direction_it_would_split(): s.settle(20) p = s.pane() for x, y, word in ( - (p["x"], p["y"] + 2, "split left"), - (p["x"] + p["w"] - 1, p["y"] + 2, "split right"), - (p["x"] + 6, p["y"] + p["h"] - 1, "split down")): + (p["x"], p["y"] + 2, "split left"), + (p["x"] + p["w"] - 1, p["y"] + 2, "split right"), + (p["x"] + 6, p["y"] + p["h"] - 1, "split down"), + ): hover(s, x, y) check(f"the border says {word}", word in bar(s), repr(bar(s))) @@ -86,13 +96,19 @@ def test_the_gap_and_the_strip_and_the_bar(): s.settle(20) left = s.panes()[0] hover(s, left["x"] + left["w"], left["y"] + 3) - check("the gap between panes offers a resize", - "drag to resize" in bar(s), repr(bar(s))) + check( + "the gap between panes offers a resize", + "drag to resize" in bar(s), + repr(bar(s)), + ) t = hit(s, "tab:") hover(s, t["x"] + 1, t["y"]) - check("a tab offers the two things you would not guess", - "rename" in bar(s) and "reorder" in bar(s), repr(bar(s))) + check( + "a tab offers the two things you would not guess", + "rename" in bar(s) and "reorder" in bar(s), + repr(bar(s)), + ) n = hit(s, "newtab") hover(s, n["x"] + 1, n["y"]) check("the new-tab button offers a new one", "new tab" in bar(s), repr(bar(s))) @@ -100,11 +116,17 @@ def test_the_gap_and_the_strip_and_the_bar(): s.send(r"\x01m") s.settle(20) gone = [p for p in s.panes() if p["w"] <= 1][0]["id"] - e = [h for h in s.snapshot().hits - if h["action"] == f"focus:{gone}" and h["h"] == 1][0] + e = [ + h + for h in s.snapshot().hits + if h["action"] == f"focus:{gone}" and h["h"] == 1 + ][0] hover(s, e["x"] + 1, e["y"]) - check("a pane put away offers to come back", - "open this pane" in bar(s), repr(bar(s))) + check( + "a pane put away offers to come back", + "open this pane" in bar(s), + repr(bar(s)), + ) def test_the_middle_is_centred_on_the_row_not_on_the_gap(): @@ -121,8 +143,11 @@ def test_the_middle_is_centred_on_the_row_not_on_the_gap(): row = bar(s) at = row.index("close this pane") want = (96 - len("close this pane")) // 2 - check("the hint is centred on the terminal", abs(at - want) <= 1, - f"at {at}, expected about {want}: {row!r}") + check( + "the hint is centred on the terminal", + abs(at - want) <= 1, + f"at {at}, expected about {want}: {row!r}", + ) def test_it_stays_put_when_the_ends_change_length(): @@ -135,8 +160,7 @@ def test_it_stays_put_when_the_ends_change_length(): for name in ("s", "medium-name", "a-really-quite-long-session-name"): with Session(SH, cols=120, rows=10) as s: s.settle(20) - s.api("set-purpose", target="tab", id=s.tabs()[0]["id"], - purpose=name) + s.api("set-purpose", target="tab", id=s.tabs()[0]["id"], purpose=name) s.settle(20) row = bar(s) check(f"the banner is up with {name!r}", "sl0ppty 0." in row, row) @@ -149,19 +173,26 @@ def test_a_full_line_drops_the_middle_rather_than_overlapping(): say which session and pane you are in, and the middle is a hint you can get again by hovering or a version you can read a moment later. So the middle is the part that disappears.""" - wordy = ["/bin/sh", "-c", - 'printf "\\033]2;a-very-long-pane-title-indeed\\007"; ' - 'stty raw -echo; cat'] + wordy = [ + "/bin/sh", + "-c", + 'printf "\\033]2;a-very-long-pane-title-indeed\\007"; stty raw -echo; cat', + ] with Session(wordy, cols=60, rows=18) as s: s.settle(20) h = hit(s, "close:") hover(s, h["x"], h["y"]) row = bar(s) - check("the hint is dropped when it would not fit clear of the ends", - "close this pane" not in row, repr(row)) - check("and both ends survive intact", - "a-very-long-pane-title-indeed" in row and "pane 1/1" in row, - repr(row)) + check( + "the hint is dropped when it would not fit clear of the ends", + "close this pane" not in row, + repr(row), + ) + check( + "and both ends survive intact", + "a-very-long-pane-title-indeed" in row and "pane 1/1" in row, + repr(row), + ) def test_it_keeps_a_blank_column_on_each_side(): @@ -171,8 +202,8 @@ def test_it_keeps_a_blank_column_on_each_side(): row = bar(s) at = row.index("sl0ppty 0.") end = at + len(row[at:].split(" ")[0]) - check("a gap before it", row[at - 1] == " ", repr(row[at - 4:at + 4])) - check("a gap after it", row[end] == " ", repr(row[end - 4:end + 4])) + check("a gap before it", row[at - 1] == " ", repr(row[at - 4 : at + 4])) + check("a gap after it", row[end] == " ", repr(row[end - 4 : end + 4])) def test_the_version_sits_in_the_slot_when_no_hint_does(): @@ -191,18 +222,20 @@ def test_the_version_sits_in_the_slot_when_no_hint_does(): check("a hint takes the slot back", "close this pane" in bar(s), bar(s)) check("and the banner gives way", "sl0ppty 0." not in bar(s), bar(s)) - hover(s, h["x"], h["y"] + 4) # off the button, into the pane + hover(s, h["x"], h["y"] + 4) # off the button, into the pane s.settle(20) - check("the banner returns when the pointer moves off", - "sl0ppty 0." in bar(s), bar(s)) + check( + "the banner returns when the pointer moves off", + "sl0ppty 0." in bar(s), + bar(s), + ) def test_the_banner_and_the_hints_are_separate_knobs(): off = cfg("version_banner false\n") with Session(SH, cols=96, rows=18, config=off) as s: s.settle(20) - check("version_banner false says nothing", "sl0ppty" not in bar(s), - bar(s)) + check("version_banner false says nothing", "sl0ppty" not in bar(s), bar(s)) s.api("split", dir="cols") s.settle(20) h = hit(s, "close:") @@ -213,8 +246,7 @@ def test_the_banner_and_the_hints_are_separate_knobs(): nohints = cfg("hints false\n") with Session(SH, cols=96, rows=18, config=nohints) as s: s.settle(20) - check("hints false leaves the banner alone", "sl0ppty 0." in bar(s), - bar(s)) + check("hints false leaves the banner alone", "sl0ppty 0." in bar(s), bar(s)) s.api("split", dir="cols") s.settle(20) h = hit(s, "close:") @@ -231,8 +263,7 @@ def test_hints_can_be_turned_off(): s.settle(20) h = hit(s, "close:") hover(s, h["x"], h["y"]) - check("hints false says nothing", "close this pane" not in bar(s), - repr(bar(s))) + check("hints false says nothing", "close this pane" not in bar(s), repr(bar(s))) os.unlink(conf) |
