Fix tests.

This commit is contained in:
Rodrigo Girão Serrão
2023-05-17 10:17:20 +01:00
parent 8399a31a46
commit 45686c8aca
6 changed files with 917 additions and 918 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,4 @@
from pathlib import Path
import sys
import pytest
@@ -78,8 +77,7 @@ def test_switches(snap_compare):
def test_input_and_focus(snap_compare):
press = [
"tab",
*"Darren", # Focus first input, write "Darren"
*"Darren", # Write "Darren"
"tab",
*"Burns", # Focus second input, write "Burns"
]
@@ -88,7 +86,7 @@ def test_input_and_focus(snap_compare):
def test_buttons_render(snap_compare):
# Testing button rendering. We press tab to focus the first button too.
assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab", "tab"])
assert snap_compare(WIDGET_EXAMPLES_DIR / "button.py", press=["tab"])
def test_placeholder_render(snap_compare):
@@ -189,7 +187,7 @@ def test_content_switcher_example_initial(snap_compare):
def test_content_switcher_example_switch(snap_compare):
assert snap_compare(
WIDGET_EXAMPLES_DIR / "content_switcher.py",
press=["tab", "tab", "enter", "wait:500"],
press=["tab", "enter", "wait:500"],
terminal_size=(50, 50),
)
@@ -315,7 +313,7 @@ def test_programmatic_scrollbar_gutter_change(snap_compare):
def test_borders_preview(snap_compare):
assert snap_compare(CLI_PREVIEWS_DIR / "borders.py", press=["tab", "enter"])
assert snap_compare(CLI_PREVIEWS_DIR / "borders.py", press=["enter"])
def test_colors_preview(snap_compare):
@@ -379,9 +377,7 @@ def test_disabled_widgets(snap_compare):
def test_focus_component_class(snap_compare):
assert snap_compare(
SNAPSHOT_APPS_DIR / "focus_component_class.py", press=["tab", "tab"]
)
assert snap_compare(SNAPSHOT_APPS_DIR / "focus_component_class.py", press=["tab"])
def test_line_api_scrollbars(snap_compare):

View File

@@ -1,5 +1,5 @@
from textual.app import App, ComposeResult
from textual.widgets import Button
from textual.widgets import Button, Input
def test_batch_update():
@@ -20,6 +20,7 @@ def test_batch_update():
class MyApp(App):
def compose(self) -> ComposeResult:
yield Input()
yield Button("Click me!")

View File

@@ -36,7 +36,7 @@ async def test_on_button_pressed() -> None:
app = ButtonApp()
async with app.run_test() as pilot:
await pilot.press("tab", "enter", "tab", "enter", "tab", "enter")
await pilot.press("enter", "tab", "enter", "tab", "enter")
await pilot.pause()
assert pressed == [

View File

@@ -38,6 +38,7 @@ async def test_empty_paste():
app = PasteApp()
async with app.run_test() as pilot:
app.set_focus(None)
await pilot.press("p")
assert app.query_one(MyInput).value == ""
assert len(paste_events) == 1

View File

@@ -39,6 +39,7 @@ async def test_radio_sets_initial_state():
async def test_click_sets_focus():
"""Clicking within a radio set should set focus."""
async with RadioSetApp().run_test() as pilot:
pilot.app.set_focus(None)
assert pilot.app.screen.focused is None
await pilot.click("#clickme")
assert pilot.app.screen.focused == pilot.app.query_one("#from_buttons")
@@ -72,8 +73,6 @@ async def test_radioset_same_button_mash():
async def test_radioset_inner_navigation():
"""Using the cursor keys should navigate between buttons in a set."""
async with RadioSetApp().run_test() as pilot:
assert pilot.app.screen.focused is None
await pilot.press("tab")
for key, landing in (
("down", 1),
("up", 0),
@@ -88,8 +87,6 @@ async def test_radioset_inner_navigation():
== pilot.app.query_one("#from_buttons").children[landing]
)
async with RadioSetApp().run_test() as pilot:
assert pilot.app.screen.focused is None
await pilot.press("tab")
assert pilot.app.screen.focused is pilot.app.screen.query_one("#from_buttons")
await pilot.press("tab")
assert pilot.app.screen.focused is pilot.app.screen.query_one("#from_strings")
@@ -101,8 +98,6 @@ async def test_radioset_inner_navigation():
async def test_radioset_breakout_navigation():
"""Shift/Tabbing while in a radioset should move to the previous/next focsuable after the set itself."""
async with RadioSetApp().run_test() as pilot:
assert pilot.app.screen.focused is None
await pilot.press("tab")
assert pilot.app.screen.focused is pilot.app.query_one("#from_buttons")
await pilot.press("tab")
assert pilot.app.screen.focused is pilot.app.query_one("#from_strings")