|
| 1 | +"""Example of waiting for all conditions to be met.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import TYPE_CHECKING, cast |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from libtmux._internal.waiter import ContentMatchType, wait_for_all_content |
| 10 | + |
| 11 | +if TYPE_CHECKING: |
| 12 | + from libtmux.session import Session |
| 13 | + |
| 14 | + |
| 15 | +@pytest.mark.example |
| 16 | +def test_wait_for_all_content(session: Session) -> None: |
| 17 | + """Demonstrate waiting for all conditions to be met.""" |
| 18 | + window = session.new_window(window_name="test_all_content") |
| 19 | + pane = window.active_pane |
| 20 | + assert pane is not None |
| 21 | + |
| 22 | + # Send commands with both required phrases |
| 23 | + pane.send_keys("echo 'Database connected'") |
| 24 | + pane.send_keys("echo 'Server started'") |
| 25 | + |
| 26 | + # Wait for all conditions to be true |
| 27 | + result = wait_for_all_content( |
| 28 | + pane, |
| 29 | + ["Database connected", "Server started"], |
| 30 | + ContentMatchType.CONTAINS, |
| 31 | + ) |
| 32 | + assert result.success |
| 33 | + # For wait_for_all_content, the matched_content will be a list of matched patterns |
| 34 | + assert result.matched_content is not None |
| 35 | + matched_content = cast("list[str]", result.matched_content) |
| 36 | + assert len(matched_content) == 2 |
| 37 | + assert "Database connected" in matched_content |
| 38 | + assert "Server started" in matched_content |
| 39 | + |
| 40 | + # Cleanup |
| 41 | + window.kill() |
0 commit comments