@@ -460,25 +460,29 @@ def expect(pane: Pane) -> PaneContentWaiter:
460
460
461
461
Examples
462
462
--------
463
- >>> # Basic usage with pane fixture
463
+ Basic usage with pane fixture:
464
+
464
465
>>> waiter = expect(pane)
465
466
>>> isinstance(waiter, PaneContentWaiter)
466
467
True
467
468
468
- >>> # Method chaining to configure the waiter
469
+ Method chaining to configure the waiter:
470
+
469
471
>>> configured_waiter = expect(pane).with_timeout(15.0).without_raising()
470
472
>>> configured_waiter.timeout
471
473
15.0
472
474
>>> configured_waiter.raises
473
475
False
474
476
475
- >>> # Equivalent to PaneContentWaiter but with a more expressive name
477
+ Equivalent to :class:`PaneContentWaiter` but with a more expressive name:
478
+
476
479
>>> expect(pane) is not PaneContentWaiter(pane) # Different instances
477
480
True
478
481
>>> type(expect(pane)) == type(PaneContentWaiter(pane)) # Same class
479
482
True
480
483
481
- >>> # A functional example showing actual usage
484
+ A functional example showing actual usage:
485
+
482
486
>>> # Send a command to the pane
483
487
>>> pane.send_keys("echo 'testing expect'", enter=True)
484
488
>>>
@@ -487,20 +491,26 @@ def expect(pane: Pane) -> PaneContentWaiter:
487
491
>>> result.success
488
492
True
489
493
>>>
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
+ ... )
497
505
>>>
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
+ ... )
504
514
"""
505
515
return PaneContentWaiter (pane )
506
516
@@ -1002,34 +1012,41 @@ def wait_for_any_content(
1002
1012
1003
1013
Examples
1004
1014
--------
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
+
1014
1026
>>> 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
+
1022
1037
>>> def has_at_least_3_lines(content):
1023
1038
... return len(content) >= 3
1024
1039
>>>
1025
1040
>>> def has_at_least_5_lines(content):
1026
1041
... return len(content) >= 5
1027
1042
>>>
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
+ ... )
1033
1050
"""
1034
1051
if not content_patterns :
1035
1052
msg = "At least one content pattern must be provided"
0 commit comments