Skip to content

Tests: Add Waiter #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

Tests: Add Waiter #579

wants to merge 5 commits into from

Conversation

tony
Copy link
Member

@tony tony commented Feb 23, 2025

Inspired by Playwright/Selenium/boto3's waiter.

Changes

feat(test): Add PaneWaiter utility for waiting on pane content

why: Tests need a reliable way to wait for pane content, especially with different shells

what:

  • Add PaneWaiter class with wait_for_content, wait_for_prompt, wait_for_text methods
  • Add WaitResult class to handle success/failure/error states
  • Add comprehensive test suite for waiter functionality

Summary by Sourcery

Adds a PaneWaiter utility class for waiting on tmux pane content in tests. This class provides methods for waiting for specific content, prompts, or text within a tmux pane, along with a WaitResult class to handle the outcome of these operations. It also includes a comprehensive test suite.

New Features:

  • Introduces a PaneWaiter class to facilitate waiting for specific content, prompts, or text within a tmux pane during tests, enhancing test reliability, especially when dealing with asynchronous shell operations.
  • Adds a WaitResult class to encapsulate the outcome of wait operations, providing details on success, the resulting value, or any errors encountered.

Tests:

  • Adds a comprehensive test suite for the PaneWaiter utility, covering scenarios such as waiting for prompts, specific text, handling timeouts, custom error messages, and custom content predicates.

Test plan

uv run pytest --cov=libtmux.test.waiter tests/test/test_waiter.py -v

Copy link

sourcery-ai bot commented Feb 23, 2025

Reviewer's Guide by Sourcery

This pull request introduces a PaneWaiter utility class to facilitate waiting for specific content or conditions within a tmux pane during testing. It also includes a comprehensive test suite to ensure the functionality and reliability of the PaneWaiter.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Introduces a PaneWaiter class for waiting on tmux pane content based on different conditions.
  • Adds a PaneWaiter class with methods for waiting on pane content.
  • Adds wait_for_content, wait_for_prompt, and wait_for_text methods to the PaneWaiter class.
  • Introduces a WaitResult dataclass to encapsulate the result of a wait operation, including success status, value, and error information.
  • Implements retry logic using retry_until to repeatedly check the pane content until the condition is met or the timeout is reached.
src/libtmux/test/waiter.py
Adds a comprehensive test suite for the PaneWaiter utility.
  • Creates tests for wait_for_prompt, wait_for_text, timeout behavior, custom error messages, and custom content predicates.
  • Sets up a new tmux window with a shell for each test case.
  • Sends keys to the pane to simulate user input and trigger content changes.
  • Asserts the success status, value, and error properties of the WaitResult object to verify the expected behavior.
tests/test/test_waiter.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented Feb 23, 2025

Codecov Report

Attention: Patch coverage is 82.92683% with 7 lines in your changes missing coverage. Please review.

Project coverage is 78.97%. Comparing base (52bf7c1) to head (db18aef).

Files with missing lines Patch % Lines
src/libtmux/test/waiter.py 82.92% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #579      +/-   ##
==========================================
+ Coverage   78.89%   78.97%   +0.08%     
==========================================
  Files          23       24       +1     
  Lines        1938     1979      +41     
  Branches      291      294       +3     
==========================================
+ Hits         1529     1563      +34     
- Misses        284      291       +7     
  Partials      125      125              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tony added 5 commits February 25, 2025 16:16
why: Tests need a reliable way to wait for pane content, especially with different shells

what:
- Add PaneWaiter class with wait_for_content, wait_for_prompt, wait_for_text methods
- Add WaitResult class to handle success/failure/error states
- Add comprehensive test suite for waiter functionality
- Fix error propagation in wait_for_content to properly handle timeouts
- Add proper type hints and fix mypy errors
- Use custom exceptions instead of generic ones in tests
- Fix code formatting and line length issues
- Update test assertions to match actual error handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant