Skip to content

Commit 90d0a71

Browse files
committed
!squash more
1 parent 829d06b commit 90d0a71

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/libtmux/test/waiter.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,6 @@ def expect(pane: Pane) -> PaneContentWaiter:
492492
True
493493
>>>
494494
495-
Real-world usage examples (showing API only, not executed):
496-
497495
Wait for text with a longer timeout:
498496
499497
>>> pane.send_keys("echo 'Operation completed", enter=True)
@@ -613,40 +611,47 @@ def wait_for_pane_content(
613611
>>> isinstance(result_pred, WaitResult)
614612
True
615613
616-
Real-world usage examples (showing API only, not executed):
617-
618-
Wait for a $ shell prompt:
614+
Wait for a `$` written on the screen (unsubmitted):
619615
620-
>>> # result = wait_for_pane_content(pane, "$", ContentMatchType.CONTAINS)
616+
>>> pane.send_keys("$")
617+
>>> result = wait_for_pane_content(pane, "$", ContentMatchType.CONTAINS)
621618
622-
Wait for exact text:
619+
Wait for exact text (unsubmitted, and fails):
623620
624-
>>> # result = wait_for_pane_content(
625-
>>> # pane,
626-
>>> # "Success",
627-
>>> # ContentMatchType.EXACT,
628-
>>> # timeout=10.0
629-
>>> # )
621+
>>> try:
622+
... pane.send_keys("echo 'Success'")
623+
... result = wait_for_pane_content(
624+
... pane,
625+
... "Success",
626+
... ContentMatchType.EXACT,
627+
... timeout=0.01
628+
... )
629+
... except WaitTimeout:
630+
... print("No exact match.")
631+
No exact match.
630632
631633
Use regex pattern matching:
632634
633635
>>> import re
634-
>>> # result = wait_for_pane_content(
635-
>>> # pane,
636-
>>> # re.compile(r"Error: .*"),
637-
>>> # ContentMatchType.REGEX
638-
>>> # )
636+
>>> pane.send_keys("echo 'Error: There was a problem.'")
637+
>>> result = wait_for_pane_content(
638+
... pane,
639+
... re.compile(r"Error: .*"),
640+
... ContentMatchType.REGEX
641+
... )
639642
640643
Use custom predicate function:
641644
642645
>>> def has_at_least_3_lines(content):
643646
... return len(content) >= 3
644647
645-
>>> # result = wait_for_pane_content(
646-
>>> # pane,
647-
>>> # has_at_least_3_lines,
648-
>>> # ContentMatchType.PREDICATE
649-
>>> # )
648+
>>> for _ in range(5):
649+
... pane.send_keys("echo 'A line'", enter=True)
650+
>>> result = wait_for_pane_content(
651+
... pane,
652+
... has_at_least_3_lines,
653+
... ContentMatchType.PREDICATE
654+
... )
650655
"""
651656
result = WaitResult(success=False)
652657

0 commit comments

Comments
 (0)