Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/support/keymap_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Run as its own interpreter: keymap discovery imports a screen nothing in it has opened.

tests/textual/test_keymap_discovery.py starts it with `python -m`, because the app test
template imports every toad module before it forks a test.
"""

import sys

from toad.key_modes import KeyMode, Standard
from toad.keymap import KeymapCatalog, KeymapRow

assert "toad.screens.welcome" not in sys.modules
catalog = KeymapCatalog.capture(tuple(KeyMode.members_with(KeyMode)))
assert "toad.screens.welcome" in sys.modules
from toad.screens.welcome import NewSessionAction # noqa: E402 - discovery imported it

row = KeymapRow.of(NewSessionAction(), Standard)
assert catalog.require(row.declaration).key_title() == NewSessionAction().key_title()
assert catalog.defaults(row) == NewSessionAction.keys[Standard.binding_mode()]
19 changes: 8 additions & 11 deletions tests/textual/test_keymap_discovery.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
"""Discovery includes screens that the current application has not opened."""

from pathlib import Path
import subprocess
import sys

from toad.key_modes import KeyMode, Standard
from toad.keymap import KeymapCatalog, KeymapRow
TESTS = Path(__file__).resolve().parents[1]


def test_unopened_screen_invocations_are_discovered_in_a_fresh_process(workspace):
# `workspace` gives this case its own interpreter, independent of other imports.
assert "toad.screens.welcome" not in sys.modules
catalog = KeymapCatalog.capture(tuple(KeyMode.members_with(KeyMode)))
assert "toad.screens.welcome" in sys.modules
from toad.screens.welcome import NewSessionAction

row = KeymapRow.of(NewSessionAction(), Standard)
assert catalog.require(row.declaration).key_title() == NewSessionAction().key_title()
assert catalog.defaults(row) == NewSessionAction.keys[Standard.binding_mode()]
# The app test template imports every toad module before it forks, so only a new
# interpreter starts without the welcome screen; `workspace` gives it this case's roots.
run = subprocess.run([sys.executable, "-m", "support.keymap_discovery"],
cwd=TESTS, capture_output=True, text=True, timeout=60)
assert run.returncode == 0, run.stderr
Loading