Skip to content

Commit 7a80a7f

Browse files
committed
test(pane): Make test_capture_pane shell-agnostic
why: Tests were failing when using fish shell due to prompt differences what: - Use PROMPT_COMMAND='' to clear shell-specific prompt commands - Set custom PS1='READY>' that works across shells - Add retry logic to wait for prompt and command output - Make assertions more flexible by checking content not exact matches
1 parent 0e4a118 commit 7a80a7f

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

tests/test_pane.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,42 @@ def test_capture_pane(session: Session) -> None:
6868
env = shutil.which("env")
6969
assert env is not None, "Cannot find usable `env` in PATH."
7070

71+
# Use PROMPT_COMMAND/PS1 to set a consistent prompt across shells
7172
session.new_window(
7273
attach=True,
7374
window_name="capture_pane",
74-
window_shell=f"{env} PS1='$ ' sh",
75+
window_shell=f"{env} PROMPT_COMMAND='' PS1='READY>' sh",
7576
)
7677
pane = session.active_window.active_pane
7778
assert pane is not None
79+
80+
def wait_for_prompt() -> bool:
81+
pane_contents = "\n".join(pane.capture_pane())
82+
return "READY>" in pane_contents
83+
84+
# Wait for shell to be ready with our custom prompt
85+
retry_until(wait_for_prompt, 1, raises=True)
86+
7887
pane_contents = "\n".join(pane.capture_pane())
79-
assert pane_contents == "$"
88+
assert "READY>" in pane_contents
89+
8090
pane.send_keys(
8191
r'printf "\n%s\n" "Hello World !"',
8292
literal=True,
8393
suppress_history=False,
8494
)
95+
96+
def wait_for_output() -> bool:
97+
pane_contents = "\n".join(pane.capture_pane())
98+
return "Hello World !" in pane_contents and pane_contents.count("READY>") >= 2
99+
100+
# Wait for command output and new prompt
101+
retry_until(wait_for_output, 1, raises=True)
102+
85103
pane_contents = "\n".join(pane.capture_pane())
86-
assert pane_contents == r'$ printf "\n%s\n" "Hello World !"{}'.format(
87-
"\n\nHello World !\n$",
88-
)
104+
assert r'READY>printf "\n%s\n" "Hello World !"' in pane_contents
105+
assert "Hello World !" in pane_contents
106+
assert pane_contents.count("READY>") >= 2
89107

90108

91109
def test_capture_pane_start(session: Session) -> None:

0 commit comments

Comments
 (0)