mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into auto-focus
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -36,3 +36,33 @@ async def test_hover_update_styles():
|
||||
# We've hovered, so ensure the pseudoclass is present and background changed
|
||||
assert button.pseudo_classes == {"enabled", "hover"}
|
||||
assert button.styles.background != initial_background
|
||||
|
||||
|
||||
def test_setting_title():
|
||||
app = MyApp()
|
||||
app.title = None
|
||||
assert app.title == "None"
|
||||
|
||||
app.title = ""
|
||||
assert app.title == ""
|
||||
|
||||
app.title = 0.125
|
||||
assert app.title == "0.125"
|
||||
|
||||
app.title = [True, False, 2]
|
||||
assert app.title == "[True, False, 2]"
|
||||
|
||||
|
||||
def test_setting_sub_title():
|
||||
app = MyApp()
|
||||
app.sub_title = None
|
||||
assert app.sub_title == "None"
|
||||
|
||||
app.sub_title = ""
|
||||
assert app.sub_title == ""
|
||||
|
||||
app.sub_title = 0.125
|
||||
assert app.sub_title == "0.125"
|
||||
|
||||
app.sub_title = [True, False, 2]
|
||||
assert app.sub_title == "[True, False, 2]"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from fractions import Fraction
|
||||
from itertools import chain
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -122,3 +123,22 @@ def test_resolve_fraction_unit():
|
||||
Fraction(32),
|
||||
resolve_dimension="width",
|
||||
) == Fraction(2)
|
||||
|
||||
|
||||
def test_resolve_issue_2502():
|
||||
"""Test https://github.com/Textualize/textual/issues/2502"""
|
||||
|
||||
widget = Widget()
|
||||
widget.styles.width = "1fr"
|
||||
widget.styles.min_width = 11
|
||||
|
||||
assert isinstance(
|
||||
resolve_fraction_unit(
|
||||
(widget.styles,),
|
||||
Size(80, 24),
|
||||
Size(80, 24),
|
||||
Fraction(10),
|
||||
resolve_dimension="width",
|
||||
),
|
||||
Fraction,
|
||||
)
|
||||
|
||||
@@ -1,58 +1,88 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from textual.app import App
|
||||
from textual.widget import Widget, WidgetError
|
||||
|
||||
|
||||
async def test_widget_move_child() -> None:
|
||||
async def test_move_child_no_direction() -> None:
|
||||
"""Test moving a widget in a child list."""
|
||||
|
||||
# Test calling move_child with no direction.
|
||||
async with App().run_test() as pilot:
|
||||
child = Widget(Widget())
|
||||
await pilot.app.mount(child)
|
||||
with pytest.raises(WidgetError):
|
||||
pilot.app.screen.move_child(child)
|
||||
|
||||
# Test calling move_child with more than one direction.
|
||||
|
||||
async def test_move_child_both_directions() -> None:
|
||||
"""Test calling move_child with more than one direction."""
|
||||
async with App().run_test() as pilot:
|
||||
child = Widget(Widget())
|
||||
await pilot.app.mount(child)
|
||||
with pytest.raises(WidgetError):
|
||||
pilot.app.screen.move_child(child, before=1, after=2)
|
||||
|
||||
# Test attempting to move a child that isn't ours.
|
||||
|
||||
async def test_move_child_not_our_child() -> None:
|
||||
"""Test attempting to move a child that isn't ours."""
|
||||
async with App().run_test() as pilot:
|
||||
child = Widget(Widget())
|
||||
await pilot.app.mount(child)
|
||||
with pytest.raises(WidgetError):
|
||||
pilot.app.screen.move_child(Widget(), before=child)
|
||||
|
||||
# Test attempting to move relative to a widget that isn't a child.
|
||||
|
||||
async def test_move_child_to_outside() -> None:
|
||||
"""Test attempting to move relative to a widget that isn't a child."""
|
||||
async with App().run_test() as pilot:
|
||||
child = Widget(Widget())
|
||||
await pilot.app.mount(child)
|
||||
with pytest.raises(WidgetError):
|
||||
pilot.app.screen.move_child(child, before=Widget())
|
||||
|
||||
# Make a background set of widgets.
|
||||
widgets = [Widget(id=f"widget-{n}") for n in range(10)]
|
||||
|
||||
# Test attempting to move past the end of the child list.
|
||||
async def test_move_child_before_itself() -> None:
|
||||
"""Test moving a widget before itself."""
|
||||
|
||||
async with App().run_test() as pilot:
|
||||
child = Widget(Widget())
|
||||
await pilot.app.mount(child)
|
||||
pilot.app.screen.move_child(child, before=child)
|
||||
|
||||
|
||||
async def test_move_child_after_itself() -> None:
|
||||
"""Test moving a widget after itself."""
|
||||
# Regression test for https://github.com/Textualize/textual/issues/1743
|
||||
async with App().run_test() as pilot:
|
||||
child = Widget(Widget())
|
||||
await pilot.app.mount(child)
|
||||
pilot.app.screen.move_child(child, after=child)
|
||||
|
||||
|
||||
async def test_move_past_end_of_child_list() -> None:
|
||||
"""Test attempting to move past the end of the child list."""
|
||||
async with App().run_test() as pilot:
|
||||
widgets = [Widget(id=f"widget-{n}") for n in range(10)]
|
||||
container = Widget(*widgets)
|
||||
await pilot.app.mount(container)
|
||||
with pytest.raises(WidgetError):
|
||||
container.move_child(widgets[0], before=len(widgets) + 10)
|
||||
|
||||
# Test attempting to move before the end of the child list.
|
||||
|
||||
async def test_move_before_end_of_child_list() -> None:
|
||||
"""Test attempting to move before the end of the child list."""
|
||||
async with App().run_test() as pilot:
|
||||
widgets = [Widget(id=f"widget-{n}") for n in range(10)]
|
||||
container = Widget(*widgets)
|
||||
await pilot.app.mount(container)
|
||||
with pytest.raises(WidgetError):
|
||||
container.move_child(widgets[0], before=-(len(widgets) + 10))
|
||||
|
||||
# Test the different permutations of moving one widget before another.
|
||||
|
||||
async def test_move_before_permutations() -> None:
|
||||
"""Test the different permutations of moving one widget before another."""
|
||||
widgets = [Widget(id=f"widget-{n}") for n in range(10)]
|
||||
perms = ((1, 0), (widgets[1], 0), (1, widgets[0]), (widgets[1], widgets[0]))
|
||||
for child, target in perms:
|
||||
async with App().run_test() as pilot:
|
||||
@@ -63,7 +93,10 @@ async def test_widget_move_child() -> None:
|
||||
assert container._nodes[1].id == "widget-0"
|
||||
assert container._nodes[2].id == "widget-2"
|
||||
|
||||
# Test the different permutations of moving one widget after another.
|
||||
|
||||
async def test_move_after_permutations() -> None:
|
||||
"""Test the different permutations of moving one widget after another."""
|
||||
widgets = [Widget(id=f"widget-{n}") for n in range(10)]
|
||||
perms = ((0, 1), (widgets[0], 1), (0, widgets[1]), (widgets[0], widgets[1]))
|
||||
for child, target in perms:
|
||||
async with App().run_test() as pilot:
|
||||
@@ -74,16 +107,22 @@ async def test_widget_move_child() -> None:
|
||||
assert container._nodes[1].id == "widget-0"
|
||||
assert container._nodes[2].id == "widget-2"
|
||||
|
||||
# Test moving after a child after the last child.
|
||||
|
||||
async def test_move_child_after_last_child() -> None:
|
||||
"""Test moving after a child after the last child."""
|
||||
async with App().run_test() as pilot:
|
||||
widgets = [Widget(id=f"widget-{n}") for n in range(10)]
|
||||
container = Widget(*widgets)
|
||||
await pilot.app.mount(container)
|
||||
container.move_child(widgets[0], after=widgets[-1])
|
||||
assert container._nodes[0].id == "widget-1"
|
||||
assert container._nodes[-1].id == "widget-0"
|
||||
|
||||
# Test moving after a child after the last child's numeric position.
|
||||
|
||||
async def test_move_child_after_last_numeric_location() -> None:
|
||||
"""Test moving after a child after the last child's numeric position."""
|
||||
async with App().run_test() as pilot:
|
||||
widgets = [Widget(id=f"widget-{n}") for n in range(10)]
|
||||
container = Widget(*widgets)
|
||||
await pilot.app.mount(container)
|
||||
container.move_child(widgets[0], after=widgets[9])
|
||||
|
||||
@@ -78,6 +78,20 @@ async def test_tree_node_expanded_message() -> None:
|
||||
assert pilot.app.messages == [("NodeExpanded", "test-tree")]
|
||||
|
||||
|
||||
async def tree_node_expanded_by_code_message() -> None:
|
||||
"""Expanding a node via the API should result in an expanded message being posted."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
pilot.app.query_one(Tree).root.children[0].expand()
|
||||
assert pilot.app.messages == [("NodeExpanded", "test-tree")]
|
||||
|
||||
|
||||
async def tree_node_all_expanded_by_code_message() -> None:
|
||||
"""Expanding all nodes via the API should result in expanded messages being posted."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
pilot.app.query_one(Tree).root.children[0].expand_all()
|
||||
assert pilot.app.messages == [("NodeExpanded", "test-tree")]
|
||||
|
||||
|
||||
async def test_tree_node_collapsed_message() -> None:
|
||||
"""Collapsing a node should result in a collapsed message being emitted."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
@@ -89,6 +103,46 @@ async def test_tree_node_collapsed_message() -> None:
|
||||
]
|
||||
|
||||
|
||||
async def tree_node_collapsed_by_code_message() -> None:
|
||||
"""Collapsing a node via the API should result in a collapsed message being posted."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
pilot.app.query_one(Tree).root.children[0].expand().collapse()
|
||||
assert pilot.app.messages == [
|
||||
("NodeExpanded", "test-tree"),
|
||||
("NodeCollapsed", "test-tree"),
|
||||
]
|
||||
|
||||
|
||||
async def tree_node_all_collapsed_by_code_message() -> None:
|
||||
"""Collapsing all nodes via the API should result in collapsed messages being posted."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
pilot.app.query_one(Tree).root.children[0].expand_all().collapse_all()
|
||||
assert pilot.app.messages == [
|
||||
("NodeExpanded", "test-tree"),
|
||||
("NodeCollapsed", "test-tree"),
|
||||
]
|
||||
|
||||
|
||||
async def tree_node_toggled_by_code_message() -> None:
|
||||
"""Toggling a node twice via the API should result in expanded and collapsed messages."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
pilot.app.query_one(Tree).root.children[0].toggle().toggle()
|
||||
assert pilot.app.messages == [
|
||||
("NodeExpanded", "test-tree"),
|
||||
("NodeCollapsed", "test-tree"),
|
||||
]
|
||||
|
||||
|
||||
async def tree_node_all_toggled_by_code_message() -> None:
|
||||
"""Toggling all nodes twice via the API should result in expanded and collapsed messages."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
pilot.app.query_one(Tree).root.children[0].toggle_all().toggle_all()
|
||||
assert pilot.app.messages == [
|
||||
("NodeExpanded", "test-tree"),
|
||||
("NodeCollapsed", "test-tree"),
|
||||
]
|
||||
|
||||
|
||||
async def test_tree_node_highlighted_message() -> None:
|
||||
"""Highlighting a node should result in a highlighted message being emitted."""
|
||||
async with TreeApp().run_test() as pilot:
|
||||
|
||||
Reference in New Issue
Block a user