aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_states.py
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-17 14:36:59 +0200
committeruser <user@clank>2026-08-17 14:36:59 +0200
commitc0022776d0912042819e4ea330cf7491a8196b45 (patch)
tree3c5d547f273d8304e7cd6834fd5a2c730a495064 /tests/test_states.py
parentsl0ppty: ruff formats the Python, and sorts its imports (diff)
downloadslosh-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_states.py')
-rw-r--r--tests/test_states.py119
1 files changed, 75 insertions, 44 deletions
diff --git a/tests/test_states.py b/tests/test_states.py
index fa1426e..bd2ab5d 100644
--- a/tests/test_states.py
+++ b/tests/test_states.py
@@ -11,6 +11,7 @@ dragged. Those are ambient contrast, which is a taste, and a taste shipped as
a default is how a tool gets a reputation for fighting you. This file asserts
that line in both directions: the first three are coloured, the fourth is not.
"""
+
import os
import sys
import tempfile
@@ -18,10 +19,13 @@ import tempfile
from harness import Session, check, report
# A pane with a screenful of known-coloured text.
-SH = ["/bin/sh", "-c",
- 'printf "\\033]2;p\\007"; i=0; '
- 'while [ $i -lt 40 ]; do printf "line %s ABCDEFGHIJKLMNOP\\n" $i; i=$((i+1)); done; '
- 'read x']
+SH = [
+ "/bin/sh",
+ "-c",
+ 'printf "\\033]2;p\\007"; i=0; '
+ 'while [ $i -lt 40 ]; do printf "line %s ABCDEFGHIJKLMNOP\\n" $i; i=$((i+1)); done; '
+ "read x",
+]
# Only the theme, so "what colour is this cell" has one answer. No states: the
# point is what sl0ppty does when you have said nothing.
@@ -47,30 +51,39 @@ def test_a_dead_pane_is_coloured_by_default():
# A *commanded* pane: only those keep their corpse by default, which is
# the only kind there is to colour.
lay = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False)
- lay.write('layout {\n tab {\n'
- ' pane command="printf \'\\\\033]2;p\\\\007\'; echo DONE; exit 3"\n'
- ' }\n}\n')
+ lay.write(
+ "layout {\n tab {\n"
+ " pane command=\"printf '\\\\033]2;p\\\\007'; echo DONE; exit 3\"\n"
+ " }\n}\n"
+ )
lay.close()
with Session(SH, cols=50, rows=10, config=cfg(), layout=lay.name) as s:
snap = s.until_text("[process exited")
- check("its contents are not left looking live",
- fg(snap, s.pane()) not in (None, "#ffffff"), str(fg(snap, s.pane())))
+ check(
+ "its contents are not left looking live",
+ fg(snap, s.pane()) not in (None, "#ffffff"),
+ str(fg(snap, s.pane())),
+ )
os.unlink(lay.name)
def test_a_suspended_pane_is_coloured_by_default():
layout = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False)
- layout.write('layout {\n tab name="t" {\n'
- ' pane command="echo hello; read x" suspended=true\n'
- ' }\n}\n')
+ layout.write(
+ 'layout {\n tab name="t" {\n'
+ ' pane command="echo hello; read x" suspended=true\n'
+ " }\n}\n"
+ )
layout.close()
with Session(SH, cols=60, rows=12, config=cfg(), layout=layout.name) as s:
s.settle(60)
pane = s.pane()
snap = s.snapshot()
- check("a pane that never started does not look like one that did",
- fg(snap, pane) not in (None, "#ffffff"),
- f"{fg(snap, pane)} — {snap.pane_text(pane)[:40]!r}")
+ check(
+ "a pane that never started does not look like one that did",
+ fg(snap, pane) not in (None, "#ffffff"),
+ f"{fg(snap, pane)} — {snap.pane_text(pane)[:40]!r}",
+ )
os.unlink(layout.name)
@@ -80,18 +93,27 @@ def test_scrollback_is_coloured_by_default():
pane = s.pane()
live = fg(s.snapshot(), pane)
- s.send(r"\x01\x1b[5~") # C-a PgUp: into the scrollback
+ s.send(r"\x01\x1b[5~") # C-a PgUp: into the scrollback
s.settle(20)
past = fg(s.snapshot(), pane)
- check("the pane is scrolled", s.panes() and "▲" in s.snapshot().screen(),
- s.snapshot().screen()[:200])
- check("looking at the past looks different from the present",
- past != live, f"live {live}, scrolled {past}")
+ check(
+ "the pane is scrolled",
+ s.panes() and "▲" in s.snapshot().screen(),
+ s.snapshot().screen()[:200],
+ )
+ check(
+ "looking at the past looks different from the present",
+ past != live,
+ f"live {live}, scrolled {past}",
+ )
- s.send(r"\x01\x1b[F") # C-a End: back to the bottom
+ s.send(r"\x01\x1b[F") # C-a End: back to the bottom
s.settle(20)
- check("and it goes back when you do", fg(s.snapshot(), pane) == live,
- f"{fg(s.snapshot(), pane)} vs {live}")
+ check(
+ "and it goes back when you do",
+ fg(s.snapshot(), pane) == live,
+ f"{fg(s.snapshot(), pane)} vs {live}",
+ )
def test_an_unfocused_pane_is_dimmed_by_default():
@@ -102,20 +124,19 @@ def test_an_unfocused_pane_is_dimmed_by_default():
with Session(SH, cols=90, rows=14, config=cfg()) as s:
s.until_text("line 39")
before = fg(s.snapshot(), s.pane())
- s.key("\\\\") # split; the left pane loses focus
+ s.key("\\\\") # split; the left pane loses focus
s.settle(40)
unfocused = [p for p in s.panes() if not p["focused"]][0]
after = fg(s.snapshot(), unfocused)
- check("the pane you left is pushed back", after != before,
- f"{before} -> {after}")
- check("but still plainly readable", after not in (None, "#000000"),
- str(after))
+ check(
+ "the pane you left is pushed back", after != before, f"{before} -> {after}"
+ )
+ check("but still plainly readable", after not in (None, "#000000"), str(after))
def test_dim_unfocused_zero_turns_it_off():
conf = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False)
- conf.write('theme { default_fg "#ffffff" default_bg "#000000" }\n'
- 'dim_unfocused 0\n')
+ conf.write('theme { default_fg "#ffffff" default_bg "#000000" }\ndim_unfocused 0\n')
conf.close()
with Session(SH, cols=90, rows=14, config=conf.name) as s:
s.until_text("line 39")
@@ -123,8 +144,11 @@ def test_dim_unfocused_zero_turns_it_off():
s.key("\\\\")
s.settle(40)
unfocused = [p for p in s.panes() if not p["focused"]][0]
- check("nothing is done to it", fg(s.snapshot(), unfocused) == before,
- f"{before} -> {fg(s.snapshot(), unfocused)}")
+ check(
+ "nothing is done to it",
+ fg(s.snapshot(), unfocused) == before,
+ f"{before} -> {fg(s.snapshot(), unfocused)}",
+ )
os.unlink(conf.name)
@@ -134,11 +158,17 @@ def test_a_states_block_beats_the_knob():
than "you did not say". (A grayscale chain makes a poor probe here — it
leaves white text white, so it looks like nothing happened.)"""
cases = [
- ('dim_unfocused 60\nstates { unfocused { tint amount=255 color="#00ff00" } }\n',
- "#00ff00", "a chain replaces the knob"),
- ('dim_unfocused 60\nstates { unfocused { } }\n',
- None, "an empty block means nothing at all"),
- ('dim_unfocused 60\n', "#c3c3c3", "and the knob applies when nobody said"),
+ (
+ 'dim_unfocused 60\nstates { unfocused { tint amount=255 color="#00ff00" } }\n',
+ "#00ff00",
+ "a chain replaces the knob",
+ ),
+ (
+ "dim_unfocused 60\nstates { unfocused { } }\n",
+ None,
+ "an empty block means nothing at all",
+ ),
+ ("dim_unfocused 60\n", "#c3c3c3", "and the knob applies when nobody said"),
]
for text, want, label in cases:
conf = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False)
@@ -159,18 +189,19 @@ def test_a_flattened_tab_still_says_which_panes_are_not_live():
(D13) — so the words have to carry what the colour carries everywhere
else. Collapsing a tab must not hide the fact."""
layout = tempfile.NamedTemporaryFile("w", suffix=".kdl", delete=False)
- layout.write('layout {\n tab name="t" {\n'
- ' pane command="stty raw -echo; cat"\n'
- ' pane command="echo hi; read x" suspended=true\n'
- ' }\n}\n')
+ layout.write(
+ 'layout {\n tab name="t" {\n'
+ ' pane command="stty raw -echo; cat"\n'
+ ' pane command="echo hi; read x" suspended=true\n'
+ " }\n}\n"
+ )
layout.close()
with Session(SH, cols=100, rows=14, config=cfg(), layout=layout.name) as s:
s.settle(60)
- s.resize(40, 12) # too small for two: the tab flattens
+ s.resize(40, 12) # too small for two: the tab flattens
s.settle(40)
screen = s.snapshot().screen()
- check("the header says the pane never started",
- "not started" in screen, screen)
+ check("the header says the pane never started", "not started" in screen, screen)
os.unlink(layout.name)