Skip to content

Commit c260e4f

Browse files
committed
!squash waiter.md doctest
1 parent 47f2473 commit c260e4f

File tree

1 file changed

+141
-130
lines changed

1 file changed

+141
-130
lines changed

src/libtmux/test/waiter.py

Lines changed: 141 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -200,31 +200,39 @@ class PaneContentWaiter:
200200
>>> hasattr(waiter, 'wait_until_ready')
201201
True
202202
203-
.. code-block:: python
204-
205-
# Real-world usage examples
206-
# Basic usage
207-
result = PaneContentWaiter(pane).wait_for_text("hello world")
208-
209-
# With options
210-
result = (
211-
PaneContentWaiter(pane)
212-
.with_timeout(10.0)
213-
.wait_for_exact_text("completed successfully")
214-
)
215-
216-
# Wait for regex pattern
217-
result = (
218-
PaneContentWaiter(pane)
219-
.with_timeout(10.0)
220-
.wait_for_regex(r"Process \d+ completed")
221-
)
222-
223-
# Custom predicate
224-
def is_ready(content):
225-
return any("ready" in line.lower() for line in content)
226-
227-
result = PaneContentWaiter(pane).wait_for_predicate(is_ready)
203+
>>> # Real-world usage examples
204+
>>> # A functional example: send text to the pane and wait for it
205+
>>> # First, send "hello world" to the pane
206+
>>> pane.send_keys("echo 'hello world'", enter=True)
207+
>>>
208+
>>> # Then wait for it to appear in the pane content
209+
>>> result = PaneContentWaiter(pane).wait_for_text("hello world")
210+
>>> result.success
211+
True
212+
>>> "hello world" in result.matched_content
213+
True
214+
>>>
215+
>>> # Basic usage (showing API only, other examples)
216+
>>> # result = PaneContentWaiter(pane).wait_for_text("other example")
217+
>>>
218+
>>> # With options
219+
>>> # result = (
220+
>>> # PaneContentWaiter(pane)
221+
>>> # .with_timeout(10.0)
222+
>>> # .wait_for_exact_text("completed successfully")
223+
>>> # )
224+
>>>
225+
>>> # Wait for regex pattern
226+
>>> # result = (
227+
>>> # PaneContentWaiter(pane)
228+
>>> # .with_timeout(10.0)
229+
>>> # .wait_for_regex(r"Process \d+ completed")
230+
>>> # )
231+
>>>
232+
>>> # Custom predicate
233+
>>> def is_ready(content):
234+
... return any("ready" in line.lower() for line in content)
235+
>>> # result = PaneContentWaiter(pane).wait_for_predicate(is_ready)
228236
"""
229237

230238
def __init__(self, pane: Pane) -> None:
@@ -455,22 +463,29 @@ def expect(pane: Pane) -> PaneContentWaiter:
455463
>>> type(expect(pane)) == type(PaneContentWaiter(pane)) # Same class
456464
True
457465
458-
.. code-block:: python
459-
460-
# Real-world usage examples
461-
# Wait for text with a longer timeout
462-
result = (
463-
expect(pane)
464-
.with_timeout(10.0)
465-
.wait_for_text("Operation completed")
466-
)
467-
468-
# Wait for a regex match without raising exceptions on timeout
469-
result = (
470-
expect(pane)
471-
.without_raising()
472-
.wait_for_regex(r"Process \d+ completed")
473-
)
466+
>>> # A functional example showing actual usage
467+
>>> # Send a command to the pane
468+
>>> pane.send_keys("echo 'testing expect'", enter=True)
469+
>>>
470+
>>> # Wait for the output using the expect function
471+
>>> result = expect(pane).wait_for_text("testing expect")
472+
>>> result.success
473+
True
474+
>>>
475+
>>> # Real-world usage examples (showing API only, not executed)
476+
>>> # Wait for text with a longer timeout
477+
>>> # result = (
478+
>>> # expect(pane)
479+
>>> # .with_timeout(10.0)
480+
>>> # .wait_for_text("Operation completed")
481+
>>> # )
482+
>>>
483+
>>> # Wait for a regex match without raising exceptions on timeout
484+
>>> # result = (
485+
>>> # expect(pane)
486+
>>> # .without_raising()
487+
>>> # .wait_for_regex(r"Process \d+ completed")
488+
>>> # )
474489
"""
475490
return PaneContentWaiter(pane)
476491

@@ -569,37 +584,35 @@ def wait_for_pane_content(
569584
>>> isinstance(result_pred, WaitResult)
570585
True
571586
572-
.. code-block:: python
573-
574-
# Real-world usage examples
575-
# Wait for a $ shell prompt
576-
result = wait_for_pane_content(pane, "$", ContentMatchType.CONTAINS)
577-
578-
# Wait for exact text
579-
result = wait_for_pane_content(
580-
pane,
581-
"Success",
582-
ContentMatchType.EXACT,
583-
timeout=10.0
584-
)
585-
586-
# Use regex pattern matching
587-
import re
588-
result = wait_for_pane_content(
589-
pane,
590-
re.compile(r"Error: .*"),
591-
ContentMatchType.REGEX
592-
)
593-
594-
# Use custom predicate function
595-
def has_at_least_3_lines(content):
596-
return len(content) >= 3
597-
598-
result = wait_for_pane_content(
599-
pane,
600-
has_at_least_3_lines,
601-
ContentMatchType.PREDICATE
602-
)
587+
>>> # Real-world usage examples (showing API only, not executed)
588+
>>> # Wait for a $ shell prompt
589+
>>> # result = wait_for_pane_content(pane, "$", ContentMatchType.CONTAINS)
590+
>>>
591+
>>> # Wait for exact text
592+
>>> # result = wait_for_pane_content(
593+
>>> # pane,
594+
>>> # "Success",
595+
>>> # ContentMatchType.EXACT,
596+
>>> # timeout=10.0
597+
>>> # )
598+
>>>
599+
>>> # Use regex pattern matching
600+
>>> import re
601+
>>> # result = wait_for_pane_content(
602+
>>> # pane,
603+
>>> # re.compile(r"Error: .*"),
604+
>>> # ContentMatchType.REGEX
605+
>>> # )
606+
>>>
607+
>>> # Use custom predicate function
608+
>>> def has_at_least_3_lines(content):
609+
... return len(content) >= 3
610+
>>>
611+
>>> # result = wait_for_pane_content(
612+
>>> # pane,
613+
>>> # has_at_least_3_lines,
614+
>>> # ContentMatchType.PREDICATE
615+
>>> # )
603616
"""
604617
result = WaitResult(success=False)
605618

@@ -974,35 +987,34 @@ def wait_for_any_content(
974987
975988
Examples
976989
--------
977-
.. code-block:: python
978-
979-
# Wait for any of the specified patterns
980-
result = wait_for_any_content(
981-
pane,
982-
["pattern1", "pattern2"],
983-
ContentMatchType.CONTAINS
984-
)
985-
986-
# Wait for any of the specified regex patterns
987-
import re
988-
result = wait_for_any_content(
989-
pane,
990-
[re.compile(r"Error: .*"), re.compile(r"Success: .*")],
991-
ContentMatchType.REGEX
992-
)
993-
994-
# Wait for any of the specified predicate functions
995-
def has_at_least_3_lines(content):
996-
return len(content) >= 3
997-
998-
def has_at_least_5_lines(content):
999-
return len(content) >= 5
1000-
1001-
result = wait_for_any_content(
1002-
pane,
1003-
[has_at_least_3_lines, has_at_least_5_lines],
1004-
ContentMatchType.PREDICATE
1005-
)
990+
>>> # Example patterns for wait_for_any_content (showing API only, not executed)
991+
>>> # Wait for any of the specified patterns
992+
>>> # result = wait_for_any_content(
993+
>>> # pane,
994+
>>> # ["pattern1", "pattern2"],
995+
>>> # ContentMatchType.CONTAINS
996+
>>> # )
997+
>>>
998+
>>> # Wait for any of the specified regex patterns
999+
>>> import re
1000+
>>> # result = wait_for_any_content(
1001+
>>> # pane,
1002+
>>> # [re.compile(r"Error: .*"), re.compile(r"Success: .*")],
1003+
>>> # ContentMatchType.REGEX
1004+
>>> # )
1005+
>>>
1006+
>>> # Wait for any of the specified predicate functions
1007+
>>> def has_at_least_3_lines(content):
1008+
... return len(content) >= 3
1009+
>>>
1010+
>>> def has_at_least_5_lines(content):
1011+
... return len(content) >= 5
1012+
>>>
1013+
>>> # result = wait_for_any_content(
1014+
>>> # pane,
1015+
>>> # [has_at_least_3_lines, has_at_least_5_lines],
1016+
>>> # ContentMatchType.PREDICATE
1017+
>>> # )
10061018
"""
10071019
if not content_patterns:
10081020
msg = "At least one content pattern must be provided"
@@ -1172,35 +1184,34 @@ def wait_for_all_content(
11721184
11731185
Examples
11741186
--------
1175-
.. code-block:: python
1176-
1177-
# Wait for all of the specified patterns
1178-
result = wait_for_all_content(
1179-
pane,
1180-
["pattern1", "pattern2"],
1181-
ContentMatchType.CONTAINS
1182-
)
1183-
1184-
# Wait for all of the specified regex patterns
1185-
import re
1186-
result = wait_for_all_content(
1187-
pane,
1188-
[re.compile(r"Error: .*"), re.compile(r"Success: .*")],
1189-
ContentMatchType.REGEX
1190-
)
1191-
1192-
# Wait for all of the specified predicate functions
1193-
def has_at_least_3_lines(content):
1194-
return len(content) >= 3
1195-
1196-
def has_at_least_5_lines(content):
1197-
return len(content) >= 5
1198-
1199-
result = wait_for_all_content(
1200-
pane,
1201-
[has_at_least_3_lines, has_at_least_5_lines],
1202-
ContentMatchType.PREDICATE
1203-
)
1187+
>>> # Example patterns for wait_for_all_content (showing API only, not executed)
1188+
>>> # Wait for all of the specified patterns
1189+
>>> # result = wait_for_all_content(
1190+
>>> # pane,
1191+
>>> # ["pattern1", "pattern2"],
1192+
>>> # ContentMatchType.CONTAINS
1193+
>>> # )
1194+
>>>
1195+
>>> # Wait for all of the specified regex patterns
1196+
>>> import re
1197+
>>> # result = wait_for_all_content(
1198+
>>> # pane,
1199+
>>> # [re.compile(r"Error: .*"), re.compile(r"Success: .*")],
1200+
>>> # ContentMatchType.REGEX
1201+
>>> # )
1202+
>>>
1203+
>>> # Wait for all of the specified predicate functions
1204+
>>> def has_at_least_3_lines(content):
1205+
... return len(content) >= 3
1206+
>>>
1207+
>>> def has_at_least_5_lines(content):
1208+
... return len(content) >= 5
1209+
>>>
1210+
>>> # result = wait_for_all_content(
1211+
>>> # pane,
1212+
>>> # [has_at_least_3_lines, has_at_least_5_lines],
1213+
>>> # ContentMatchType.PREDICATE
1214+
>>> # )
12041215
"""
12051216
if not content_patterns:
12061217
msg = "At least one content pattern must be provided"

0 commit comments

Comments
 (0)