Skip to content

Commit f1b8854

Browse files
committed
!squash waiter
1 parent 6a88af7 commit f1b8854

File tree

1 file changed

+55
-38
lines changed

1 file changed

+55
-38
lines changed

src/libtmux/test/waiter.py

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -460,25 +460,29 @@ def expect(pane: Pane) -> PaneContentWaiter:
460460
461461
Examples
462462
--------
463-
>>> # Basic usage with pane fixture
463+
Basic usage with pane fixture:
464+
464465
>>> waiter = expect(pane)
465466
>>> isinstance(waiter, PaneContentWaiter)
466467
True
467468
468-
>>> # Method chaining to configure the waiter
469+
Method chaining to configure the waiter:
470+
469471
>>> configured_waiter = expect(pane).with_timeout(15.0).without_raising()
470472
>>> configured_waiter.timeout
471473
15.0
472474
>>> configured_waiter.raises
473475
False
474476
475-
>>> # Equivalent to PaneContentWaiter but with a more expressive name
477+
Equivalent to :class:`PaneContentWaiter` but with a more expressive name:
478+
476479
>>> expect(pane) is not PaneContentWaiter(pane) # Different instances
477480
True
478481
>>> type(expect(pane)) == type(PaneContentWaiter(pane)) # Same class
479482
True
480483
481-
>>> # A functional example showing actual usage
484+
A functional example showing actual usage:
485+
482486
>>> # Send a command to the pane
483487
>>> pane.send_keys("echo 'testing expect'", enter=True)
484488
>>>
@@ -487,20 +491,26 @@ def expect(pane: Pane) -> PaneContentWaiter:
487491
>>> result.success
488492
True
489493
>>>
490-
>>> # Real-world usage examples (showing API only, not executed)
491-
>>> # Wait for text with a longer timeout
492-
>>> # result = (
493-
>>> # expect(pane)
494-
>>> # .with_timeout(10.0)
495-
>>> # .wait_for_text("Operation completed")
496-
>>> # )
494+
495+
Real-world usage examples (showing API only, not executed):
496+
497+
Wait for text with a longer timeout:
498+
499+
>>> pane.send_keys("echo 'Operation completed", enter=True)
500+
>>> result = (
501+
... expect(pane)
502+
... .with_timeout(10.0)
503+
... .wait_for_text("Operation completed")
504+
... )
497505
>>>
498-
>>> # Wait for a regex match without raising exceptions on timeout
499-
>>> # result = (
500-
>>> # expect(pane)
501-
>>> # .without_raising()
502-
>>> # .wait_for_regex(r"Process \d+ completed")
503-
>>> # )
506+
507+
Wait for a regex match without raising exceptions on timeout:
508+
>>> pane.send_keys("echo 'Process 19 completed'", enter=True)
509+
>>> result = (
510+
... expect(pane)
511+
... .without_raising()
512+
... .wait_for_regex(r"Process \d+ completed")
513+
... )
504514
"""
505515
return PaneContentWaiter(pane)
506516

@@ -1002,34 +1012,41 @@ def wait_for_any_content(
10021012
10031013
Examples
10041014
--------
1005-
>>> # Example patterns for wait_for_any_content (showing API only, not executed)
1006-
>>> # Wait for any of the specified patterns
1007-
>>> # result = wait_for_any_content(
1008-
>>> # pane,
1009-
>>> # ["pattern1", "pattern2"],
1010-
>>> # ContentMatchType.CONTAINS
1011-
>>> # )
1012-
>>>
1013-
>>> # Wait for any of the specified regex patterns
1015+
Wait for any of the specified patterns:
1016+
1017+
>>> pane.send_keys("echo 'pattern2'", enter=True)
1018+
>>> result = wait_for_any_content(
1019+
... pane,
1020+
... ["pattern1", "pattern2"],
1021+
... ContentMatchType.CONTAINS
1022+
... )
1023+
1024+
Wait for any of the specified regex patterns:
1025+
10141026
>>> import re
1015-
>>> # result = wait_for_any_content(
1016-
>>> # pane,
1017-
>>> # [re.compile(r"Error: .*"), re.compile(r"Success: .*")],
1018-
>>> # ContentMatchType.REGEX
1019-
>>> # )
1020-
>>>
1021-
>>> # Wait for any of the specified predicate functions
1027+
>>> pane.send_keys("echo 'Error: this did not do the trick'", enter=True)
1028+
>>> pane.send_keys("echo 'Success: But subsequently this worked'", enter=True)
1029+
>>> result = wait_for_any_content(
1030+
... pane,
1031+
... [re.compile(r"Error: .*"), re.compile(r"Success: .*")],
1032+
... ContentMatchType.REGEX
1033+
... )
1034+
1035+
Wait for any of the specified predicate functions:
1036+
10221037
>>> def has_at_least_3_lines(content):
10231038
... return len(content) >= 3
10241039
>>>
10251040
>>> def has_at_least_5_lines(content):
10261041
... return len(content) >= 5
10271042
>>>
1028-
>>> # result = wait_for_any_content(
1029-
>>> # pane,
1030-
>>> # [has_at_least_3_lines, has_at_least_5_lines],
1031-
>>> # ContentMatchType.PREDICATE
1032-
>>> # )
1043+
>>> for _ in range(5):
1044+
... pane.send_keys("echo 'A line'", enter=True)
1045+
>>> result = wait_for_any_content(
1046+
... pane,
1047+
... [has_at_least_3_lines, has_at_least_5_lines],
1048+
... ContentMatchType.PREDICATE
1049+
... )
10331050
"""
10341051
if not content_patterns:
10351052
msg = "At least one content pattern must be provided"

0 commit comments

Comments
 (0)