Skip to content

Commit

Permalink
Update snapshots, add ability to pass App instance into snap_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jul 21, 2024
1 parent ac9e38b commit 1c34986
Show file tree
Hide file tree
Showing 28 changed files with 2,554 additions and 2,563 deletions.
Binary file modified .coverage
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
239 changes: 119 additions & 120 deletions tests/__snapshots__/test_snapshots/TestConfig.test_config.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
176 changes: 88 additions & 88 deletions tests/__snapshots__/test_snapshots/TestJumpMode.test_click_switch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
176 changes: 88 additions & 88 deletions tests/__snapshots__/test_snapshots/TestJumpMode.test_focus_switch.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
184 changes: 92 additions & 92 deletions tests/__snapshots__/test_snapshots/TestJumpMode.test_loads.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
237 changes: 118 additions & 119 deletions tests/__snapshots__/test_snapshots/TestSendRequest.test_send_request.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
190 changes: 95 additions & 95 deletions tests/__snapshots__/test_snapshots/TestUrlBar.test_enter_url.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 16 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from os import PathLike
from pathlib import Path, PurePath
from tempfile import mkdtemp
from typing import Awaitable, Union, Optional, Callable, Iterable, TYPE_CHECKING
from typing import Any, Awaitable, Union, Optional, Callable, Iterable, TYPE_CHECKING

import pytest
from _pytest.config import ExitCode
Expand All @@ -21,10 +21,10 @@
from rich.console import Console
from syrupy import SnapshotAssertion
from syrupy.extensions.single_file import SingleFileSnapshotExtension, WriteMode
from textual.app import App

if TYPE_CHECKING:
from _pytest.nodes import Item
from textual.app import App
from textual.pilot import Pilot


Expand Down Expand Up @@ -124,7 +124,7 @@ def snap_compare(
snapshot = snapshot.use_extension(SVGImageExtension)

def compare(
app_path: str | PurePath,
app_path: str | PurePath | App[Any],
press: Iterable[str] = (),
terminal_size: tuple[int, int] = (80, 24),
run_before: Callable[[Pilot], Awaitable[None] | None] | None = None,
Expand All @@ -150,16 +150,20 @@ def compare(
from textual._import_app import import_app

node = request.node
path = Path(app_path)
if path.is_absolute():
# If the user supplies an absolute path, just use it directly.
app = import_app(str(path.resolve()))

if isinstance(app_path, App):
app = app_path
else:
# If a relative path is supplied by the user, it's relative to the location of the pytest node,
# NOT the location that `pytest` was invoked from.
node_path = node.path.parent
resolved = (node_path / app_path).resolve()
app = import_app(str(resolved))
path = Path(app_path)
if path.is_absolute():
# If the user supplies an absolute path, just use it directly.
app = import_app(str(path.resolve()))
else:
# If a relative path is supplied by the user, it's relative to the location of the pytest node,
# NOT the location that `pytest` was invoked from.
node_path = node.path.parent
resolved = (node_path / app_path).resolve()
app = import_app(str(resolved))

from textual._doc import take_svg_screenshot

Expand Down
10 changes: 5 additions & 5 deletions tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_request_loaded_into_view__headers(self, snap_compare):

async def run_before(pilot: Pilot):
# Navigate to 'get one post' and select it.
await pilot.press("J", "J", "j")
await pilot.press(*"Jj")
await pilot.press("enter")

assert snap_compare(POSTING_MAIN, run_before=run_before, terminal_size=(80, 34))
Expand All @@ -261,7 +261,7 @@ def test_request_loaded_into_view__body(self, snap_compare):

async def run_before(pilot: Pilot):
# Navigate to 'POST one post' and select it.
await pilot.press("J", "J", "j", "j")
await pilot.press(*"JJjjj")
await pilot.press("enter")
await pilot.press("ctrl+o", "w") # jump to 'Body' tab

Expand All @@ -272,7 +272,7 @@ def test_request_loaded_into_view__query_params(self, snap_compare):

async def run_before(pilot: Pilot):
# Navigate to 'GET comments via query' and select it.
await pilot.press("J", "J", "J", "j", "j")
await pilot.press(*"JJJjj")
await pilot.press("enter")
await pilot.press("ctrl+o", "e") # jump to 'Query Params' tab

Expand All @@ -283,7 +283,7 @@ def test_request_loaded_into_view__auth(self, snap_compare):

async def run_before(pilot: Pilot):
# Navigate to 'GET comments via query' and select it.
await pilot.press("j")
await pilot.press(*"jj")
await pilot.press("enter")
await pilot.press("ctrl+o", "r") # jump to 'Auth' tab

Expand All @@ -306,7 +306,7 @@ def test_request_loaded_into_view__options(self, snap_compare):
"""Check that the request options are loaded into the view."""

async def run_before(pilot: Pilot):
await pilot.press("j")
await pilot.press(*"jj")
await pilot.press("enter")
await pilot.press("ctrl+o", "y") # jump to 'Options' tab

Expand Down

0 comments on commit 1c34986

Please sign in to comment.