Skip to content

Commit

Permalink
Adding initial snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns committed Jul 20, 2024
1 parent df13be2 commit 007bf7e
Show file tree
Hide file tree
Showing 6 changed files with 1,009 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/posting/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def import_spec(spec_path: str, output: str | None) -> None:


def make_posting(
collection: Path, env: tuple[str, ...] = (), using_default_collection: bool = False
collection: Path,
env: tuple[str, ...] = (),
using_default_collection: bool = False,
) -> Posting:
"""Return a Posting instance with the given collection and environment."""
collection_tree = Collection.from_directory(str(collection.resolve()))
Expand Down
8 changes: 7 additions & 1 deletion src/posting/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from contextvars import ContextVar
import os
from pathlib import Path
from typing import Literal, Type
from pydantic import BaseModel, Field, SecretStr
from pydantic_settings import (
Expand Down Expand Up @@ -129,7 +130,12 @@ def settings_customise_sources(
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]:
conf_file = config_file()
config_from_env = os.getenv("POSTING_CONFIG_FILE")
if config_from_env:
conf_file = Path(config_from_env).resolve()
else:
conf_file = config_file()

default_sources = (
init_settings,
env_settings,
Expand Down
956 changes: 956 additions & 0 deletions tests/__snapshots__/test_snapshots.ambr

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion tests/posting_snapshot_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
EXTRA_ENV = COLLECTION / "sample_extra.env"

envs = tuple(str(env) for env in [BASE_ENV, EXTRA_ENV])

app = make_posting(collection=COLLECTION, env=envs)
# app.run()
2 changes: 2 additions & 0 deletions tests/sample-configs/general.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
heading:
show_host: false
43 changes: 41 additions & 2 deletions tests/test_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import os
from pathlib import Path
from unittest import mock

from textual.pilot import Pilot
from textual.widgets import Input
from textual.widgets import Input, TextArea

SNAPSHOT_DIR = Path(__file__).parent
CONFIG_DIR = SNAPSHOT_DIR / "sample-configs"
POSTING_MAIN = SNAPSHOT_DIR / "posting_snapshot_app.py"

POSTING_MAIN = Path(__file__).parent / "posting_snapshot_app.py"

def use_config(file_name: str):
return mock.patch.dict(
os.environ, {"POSTING_CONFIG_FILE": str(CONFIG_DIR / file_name)}
)


def no_cursor_blink(pilot: Pilot):
for input in pilot.app.query(Input):
input.cursor_blink = False
for text_area in pilot.app.query(TextArea):
text_area.cursor_blink = False


@use_config("general.yaml")
class TestJumpMode:
def test_loads(self, snap_compare):
"""Simple check that ctrl+o enters jump mode."""
Expand Down Expand Up @@ -41,3 +53,30 @@ async def run_before(pilot: Pilot):
await pilot.press("y") # target "Options" tab

assert snap_compare(POSTING_MAIN, run_before=run_before)


@use_config("general.yaml")
class TestMethodSelection:
def test_select_post_method(self, snap_compare):
"""Simple check that we can change the method."""

async def run_before(pilot: Pilot):
no_cursor_blink(pilot)
await pilot.press("ctrl+t")
await pilot.press("p")
await pilot.press("enter")

assert snap_compare(POSTING_MAIN, run_before=run_before)


@use_config("general.yaml")
class TestUrlBar:
def test_enter_url(self, snap_compare) -> None:
"""Check that we can enter a URL into the URL bar."""

async def run_before(pilot: Pilot) -> None:
no_cursor_blink(pilot)
await pilot.press("ctrl+l") # Focus the URL bar
await pilot.press(*"https://example.com/")

assert snap_compare(POSTING_MAIN, run_before=run_before)

0 comments on commit 007bf7e

Please sign in to comment.