aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_session.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_session.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 '')
-rw-r--r--tests/test_session.py80
1 files changed, 52 insertions, 28 deletions
diff --git a/tests/test_session.py b/tests/test_session.py
index f8aa30d..cd6ab58 100644
--- a/tests/test_session.py
+++ b/tests/test_session.py
@@ -4,6 +4,7 @@
The point of the whole milestone is that the session outlives the client, so
the assertions are about what survives: content, layout, and the process.
"""
+
import fcntl
import os
import pty
@@ -16,7 +17,10 @@ import termios
import time
import uuid
-BIN = os.environ.get("SL0PPTY_BIN", os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "build", "sl0ppty"))
+BIN = os.environ.get(
+ "SL0PPTY_BIN",
+ os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "build", "sl0ppty"),
+)
fails = 0
@@ -62,8 +66,9 @@ def drain(fd, idle=0.3, limit=3.0):
def control(name, line):
- out = subprocess.run([BIN, "-s", name, "cmd", line],
- capture_output=True, text=True, timeout=10)
+ out = subprocess.run(
+ [BIN, "-s", name, "cmd", line], capture_output=True, text=True, timeout=10
+ )
return out.stdout.strip()
@@ -88,21 +93,30 @@ def main():
drain(fd)
os.write(fd, b"marker-alpha")
out = drain(fd)
- check("a session starts and shows typed text", b"marker-alpha" in out,
- repr(out[-80:]))
+ check(
+ "a session starts and shows typed text", b"marker-alpha" in out, repr(out[-80:])
+ )
- check("the session is listed as running",
- name in subprocess.run([BIN, "ls"], capture_output=True, text=True).stdout,
- "")
+ check(
+ "the session is listed as running",
+ name in subprocess.run([BIN, "ls"], capture_output=True, text=True).stdout,
+ "",
+ )
# --- split, so the layout is worth preserving -----------------------
os.write(fd, b"\x01\\")
drain(fd)
panes_before = control(name, "panes")
- check("control socket answers while attached", panes_before.startswith("["),
- panes_before[:60])
- check("the split is visible to the control socket",
- panes_before.count('"id"') == 2, panes_before[:120])
+ check(
+ "control socket answers while attached",
+ panes_before.startswith("["),
+ panes_before[:60],
+ )
+ check(
+ "the split is visible to the control socket",
+ panes_before.count('"id"') == 2,
+ panes_before[:120],
+ )
# --- probes must not disturb the client -----------------------------
# Regression: `ls` connects to check liveness. When a connection counted
@@ -118,8 +132,7 @@ def main():
os.write(fd, b"-still-here")
out = drain(fd)
- check("the client survived 40 connections", b"still-here" in out,
- repr(out[-80:]))
+ check("the client survived 40 connections", b"still-here" in out, repr(out[-80:]))
# --- detach ---------------------------------------------------------
os.write(fd, b"\x01d")
@@ -130,24 +143,32 @@ def main():
# --- the session must still be there --------------------------------
time.sleep(0.2)
panes_after = control(name, "panes")
- check("the session outlives its client", panes_after.startswith("["),
- panes_after[:60])
- check("the layout survived the detach",
- panes_after.count('"id"') == 2, panes_after[:120])
+ check(
+ "the session outlives its client", panes_after.startswith("["), panes_after[:60]
+ )
+ check(
+ "the layout survived the detach",
+ panes_after.count('"id"') == 2,
+ panes_after[:120],
+ )
snap = control(name, "snapshot text")
- check("pane content survived the detach", "marker-alpha" in snap,
- repr(snap[:120]))
- check("a detached session can still be driven",
- control(name, "raw \\r\\ntyped-while-detached") == ""
- and "typed-while-detached" in control(name, "snapshot text"),
- repr(control(name, "snapshot text")[:200]))
+ check("pane content survived the detach", "marker-alpha" in snap, repr(snap[:120]))
+ check(
+ "a detached session can still be driven",
+ control(name, "raw \\r\\ntyped-while-detached") == ""
+ and "typed-while-detached" in control(name, "snapshot text"),
+ repr(control(name, "snapshot text")[:200]),
+ )
# --- reattach -------------------------------------------------------
pid2, fd2 = attach(name)
out = drain(fd2)
- check("reattaching repaints the whole screen", b"marker-alpha" in out,
- repr(out[-120:]))
+ check(
+ "reattaching repaints the whole screen",
+ b"marker-alpha" in out,
+ repr(out[-120:]),
+ )
check("reattached client can still type", True)
os.write(fd2, b"-beta")
out = drain(fd2)
@@ -157,8 +178,11 @@ def main():
pid3, fd3 = attach(name)
drain(fd3)
tail = drain(fd2, idle=0.2, limit=2.0)
- check("the displaced client is told it was replaced",
- b"replaced" in tail or wait_gone(pid2, 1.0), repr(tail[-60:]))
+ check(
+ "the displaced client is told it was replaced",
+ b"replaced" in tail or wait_gone(pid2, 1.0),
+ repr(tail[-60:]),
+ )
# --- closing the last pane ends the session -------------------------
os.write(fd3, b"\x01x") # close pane 2