Repository navigation
feat: improvements for PyPI publishing and testing #13
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
Draft
rishitank
wants to merge
8
commits into
main
Choose a base branch
from
feature/improvements-and-pypi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3eecdc5
feat: improvements for PyPI publishing and testing
rishitank 4a23177
docs: fix markdownlint MD022/MD031/MD040 and align architecture box
rishitank 53c7dc7
test: share tool fixtures via conftest, fix pooled_context mock, add β¦
rishitank c370ecc
perf(diff): build the diff highlight overlay with a mask instead of gβ¦
rishitank 71efe3a
test: document the pooled_context stand-in in conftest
rishitank e13577c
test: clean up the diff image even when an assertion fails
rishitank d7b2d4a
Merge branch 'main' into feature/improvements-and-pypi
rishitank 964484e
test: assert device filtering and device forwarding explicitly
rishitank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Shared pytest fixtures for AnimaWatch tests.""" | ||
|
|
||
| from collections.abc import AsyncIterator | ||
| from contextlib import asynccontextmanager | ||
| from pathlib import Path | ||
| from typing import Any | ||
| from unittest.mock import AsyncMock, MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from animawatch.server import AppContext | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_page() -> MagicMock: | ||
| """A Playwright ``Page`` stand-in with awaitable navigation and evaluation.""" | ||
| page = MagicMock() | ||
| page.goto = AsyncMock() | ||
| page.evaluate = AsyncMock(return_value={}) | ||
| return page | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_app_context(mock_page: MagicMock, tmp_path: Path) -> AppContext: | ||
| """An AppContext whose browser and vision provider are mocks. | ||
|
|
||
| ``browser.pooled_context`` behaves like the real async context manager: calling | ||
| it returns an object usable in ``async with`` that yields ``(context, page)``. | ||
| It is wrapped in a ``MagicMock`` so tests can assert how it was called. | ||
| """ | ||
| mock_browser = AsyncMock() | ||
| # Paths live under tmp_path so tools that unlink them can't touch real files. | ||
| mock_browser.record_interaction = AsyncMock(return_value=tmp_path / "video.webm") | ||
| mock_browser.take_screenshot = AsyncMock(return_value=tmp_path / "screenshot.png") | ||
|
|
||
| @asynccontextmanager | ||
| async def pooled_context(*_args: Any, **_kwargs: Any) -> AsyncIterator[tuple[Any, Any]]: | ||
| """Yield a ``(context, page)`` pair like ``BrowserRecorder.pooled_context``.""" | ||
| yield (MagicMock(), mock_page) | ||
|
|
||
| mock_browser.pooled_context = MagicMock(side_effect=pooled_context) | ||
|
|
||
| mock_vision = AsyncMock() | ||
| mock_vision.analyze_video = AsyncMock(return_value="Video analysis result") | ||
| mock_vision.analyze_image = AsyncMock(return_value="Image analysis result") | ||
|
|
||
| return AppContext( | ||
| browser=mock_browser, | ||
| vision=mock_vision, | ||
| recordings={}, | ||
| analyses={}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_ctx(mock_app_context: AppContext) -> MagicMock: | ||
| """A tool ``Context`` whose lifespan context is ``mock_app_context``.""" | ||
| ctx = MagicMock() | ||
| ctx.request_context.lifespan_context = mock_app_context | ||
| return ctx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.