Skip to content

Tests: Improve shell interoperability #577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Next Next commit
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
  • Loading branch information
tony committed Feb 25, 2025
commit 7a80a7f8646587e560c399e54c55f4a76e4df24e
28 changes: 23 additions & 5 deletions tests/test_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,42 @@ def test_capture_pane(session: Session) -> None:
env = shutil.which("env")
assert env is not None, "Cannot find usable `env` in PATH."

# Use PROMPT_COMMAND/PS1 to set a consistent prompt across shells
session.new_window(
attach=True,
window_name="capture_pane",
window_shell=f"{env} PS1='$ ' sh",
window_shell=f"{env} PROMPT_COMMAND='' PS1='READY>' sh",
)
pane = session.active_window.active_pane
assert pane is not None

def wait_for_prompt() -> bool:
pane_contents = "\n".join(pane.capture_pane())
return "READY>" in pane_contents

# Wait for shell to be ready with our custom prompt
retry_until(wait_for_prompt, 1, raises=True)

pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == "$"
assert "READY>" in pane_contents

pane.send_keys(
r'printf "\n%s\n" "Hello World !"',
literal=True,
suppress_history=False,
)

def wait_for_output() -> bool:
pane_contents = "\n".join(pane.capture_pane())
return "Hello World !" in pane_contents and pane_contents.count("READY>") >= 2

# Wait for command output and new prompt
retry_until(wait_for_output, 1, raises=True)

pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == r'$ printf "\n%s\n" "Hello World !"{}'.format(
"\n\nHello World !\n$",
)
assert r'READY>printf "\n%s\n" "Hello World !"' in pane_contents
assert "Hello World !" in pane_contents
assert pane_contents.count("READY>") >= 2


def test_capture_pane_start(session: Session) -> None:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy