code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
def test_add_separator(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5431
You should see a button on the left. On the right an option list with Option 1, separator, Option 3
"""
class FocusTest(App[None]):
CSS = """
OptionList {
height: 1fr;
}
"""
counter: var[int] = var(0)
def compose(self) -> ComposeResult:
with Horizontal():
yield Button("Add")
yield OptionList()
@on(Button.Pressed)
def add_more_stuff(self) -> None:
self.counter += 1
self.query_one(OptionList).add_option(
(f"This is option {self.counter}" if self.counter % 2 else None)
)
async def run_before(pilot: Pilot) -> None:
await pilot.pause()
for _ in range(3):
await pilot.click(Button)
await pilot.pause(0.4)
assert snap_compare(FocusTest(), run_before=run_before) | Regression test for https://github.com/Textualize/textual/issues/5431
You should see a button on the left. On the right an option list with Option 1, separator, Option 3 | test_add_separator | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def test_visual_tooltip(snap_compare):
"""Test Visuals such as Content work in tooltips.
You should see a tooltip under a label.
The tooltip should have the word "Tooltip" highlighted in the accent color.
"""
class TooltipApp(App[None]):
TOOLTIP_DELAY = 0.4
def compose(self) -> ComposeResult:
progress_bar = Label("Hello, World")
progress_bar.tooltip = Content.from_markup(
"Hello, [bold $accent]Tooltip[/]!"
)
yield progress_bar
async def run_before(pilot: Pilot) -> None:
await pilot.pause()
await pilot.hover(Label)
await pilot.pause(0.4)
await pilot.pause()
assert snap_compare(TooltipApp(), run_before=run_before) | Test Visuals such as Content work in tooltips.
You should see a tooltip under a label.
The tooltip should have the word "Tooltip" highlighted in the accent color. | test_visual_tooltip | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
with TabbedContent():
with TabPane("Title Slide", id="title-slide-tab"):
yield Container(RichLog(id="title-rich-log"), id="title-container") | Create child widgets for the app. | test_auto_rich_log_width.compose | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def on_mount(self) -> None:
"""Add some text to the RichLogs."""
title_rich_log = self.query_one("#title-rich-log", RichLog)
title_rich_log.write("This is the Title Slide RichLog") | Add some text to the RichLogs. | test_auto_rich_log_width.on_mount | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def test_auto_rich_log_width(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5472
You should see a tabbed content with a single line of text in the middle of the page.
"""
class MinimalApp(App):
"""A minimal Textual app demonstrating the RichLog border issue."""
CSS = """
TabbedContent {
height: 100%;
}
#title-container {
align: center middle;
}
#title-rich-log {
overflow-y: auto;
background: black 0%;
background: blue;
width: auto;
height: auto;
/* When removing the border, the whole thing is gone? */
# border: solid green 0%;
}
"""
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
with TabbedContent():
with TabPane("Title Slide", id="title-slide-tab"):
yield Container(RichLog(id="title-rich-log"), id="title-container")
def on_mount(self) -> None:
"""Add some text to the RichLogs."""
title_rich_log = self.query_one("#title-rich-log", RichLog)
title_rich_log.write("This is the Title Slide RichLog")
assert snap_compare(MinimalApp()) | Regression test for https://github.com/Textualize/textual/issues/5472
You should see a tabbed content with a single line of text in the middle of the page. | test_auto_rich_log_width | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def compose(self) -> ComposeResult:
"""
Create the user interface
"""
self.last_updated = Label(f"Last Updated: NOW", id="last_updated")
yield Header()
yield Vertical(
DataTable(id="datatable"),
Horizontal(
Button("OK", variant="primary", id="ok"),
Button("Cancel", variant="error", id="cancel"),
self.last_updated,
id="button_row",
),
id="main_tab",
) | Create the user interface | test_auto_in_auto.compose | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def test_auto_in_auto(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5550
You should see a table, with a bar at the bottom.
The bottom bar should have some text right aligned, and two centered buttons in the center of
the remaining space.
"""
class MyApp(App):
CSS = """
MyApp {
align: center middle;
#datatable {
height: 1fr;
}
Horizontal {
height: auto;
}
#button_row {
align: center middle;
}
Button {
margin: 1;
height: auto;
}
#last_updated {
dock: right;
offset: 0 2;
}
Label {
height: auto;
}
}
"""
def compose(self) -> ComposeResult:
"""
Create the user interface
"""
self.last_updated = Label(f"Last Updated: NOW", id="last_updated")
yield Header()
yield Vertical(
DataTable(id="datatable"),
Horizontal(
Button("OK", variant="primary", id="ok"),
Button("Cancel", variant="error", id="cancel"),
self.last_updated,
id="button_row",
),
id="main_tab",
)
def on_mount(self) -> None:
rows = [
(
"Name",
"Occupation",
"Country",
),
(
"Mike",
"Python Wrangler",
"USA",
),
(
"Bill",
"Engineer",
"UK",
),
("Dee", "Manager", "Germany"),
]
table = self.query_one(DataTable)
table.clear(columns=True)
table.add_columns(*rows[0])
table.add_rows(rows[1:])
assert snap_compare(MyApp()) | Regression test for https://github.com/Textualize/textual/issues/5550
You should see a table, with a bar at the bottom.
The bottom bar should have some text right aligned, and two centered buttons in the center of
the remaining space. | test_auto_in_auto | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def test_panel_border_title_colors(snap_compare):
"""Regression test for https://github.com/Textualize/textual/issues/5548
You should see four labels with panel type borders. The border title colors
should match the description in the label."""
class BorderTitleApp(App):
CSS = """
Label {
border: panel red;
width: 40;
margin: 1;
}
.with-border-title-color {
border-title-color: yellow;
}
.with-border-title-background {
border-title-background: green;
}
"""
def compose(self) -> ComposeResult:
yield Label(
"with default",
)
yield Label(
"with yellow color",
classes="with-border-title-color",
)
yield Label(
"with green background",
classes="with-border-title-background",
)
yield Label(
"with yellow color and green background",
classes="with-border-title-background with-border-title-color",
)
def on_mount(self) -> None:
for label in self.query(Label):
label.border_title = "Border title"
assert snap_compare(BorderTitleApp()) | Regression test for https://github.com/Textualize/textual/issues/5548
You should see four labels with panel type borders. The border title colors
should match the description in the label. | test_panel_border_title_colors | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def test_click_selection_disabled_when_allow_select_is_false(
widget_allow_select, screen_allow_select, app_allow_select, snap_compare
):
"""Regression test for https://github.com/Textualize/textual/issues/5627"""
class AllowSelectWidget(Label):
ALLOW_SELECT = widget_allow_select
class AllowSelectScreen(Screen):
ALLOW_SELECT = screen_allow_select
def compose(self) -> ComposeResult:
should_select = (
widget_allow_select and screen_allow_select and app_allow_select
)
yield AllowSelectWidget(
f"Double-clicking me {'SHOULD' if should_select else 'SHOULD NOT'} select the text"
)
class AllowSelectApp(App):
ALLOW_SELECT = app_allow_select
def on_mount(self) -> None:
self.push_screen(AllowSelectScreen())
async def run_before(pilot: Pilot) -> None:
await pilot.pause()
await pilot.click(Label, times=2)
assert snap_compare(AllowSelectApp(), run_before=run_before) | Regression test for https://github.com/Textualize/textual/issues/5627 | test_click_selection_disabled_when_allow_select_is_false | python | Textualize/textual | tests/snapshot_tests/test_snapshots.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/test_snapshots.py | MIT |
def compose(self) -> ComposeResult:
with Horizontal():
for document in MARKDOWN:
yield Markdown(document)
yield Markdown("""```python
# Two spaces: see?
class Foo:
'''This is a doc string.'''
some_code(1, 2, 3, 4)
```
""", classes="code") | This is a doc string. | compose | python | Textualize/textual | tests/snapshot_tests/snapshot_apps/markdown_whitespace.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/snapshot_apps/markdown_whitespace.py | MIT |
def compose(self) -> ComposeResult:
"""Compose the child widgets."""
yield Label("This should not cause a scrollbar to appear") | Compose the child widgets. | compose | python | Textualize/textual | tests/snapshot_tests/snapshot_apps/layer_fix.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/snapshot_apps/layer_fix.py | MIT |
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
with TabbedContent("Workflows"):
yield DataTable(id="table") | Create child widgets for the app. | compose | python | Textualize/textual | tests/snapshot_tests/snapshot_apps/data_table_tabs.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/snapshot_apps/data_table_tabs.py | MIT |
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Header()
yield Static(" Profile ", id="title")
yield Profile()
yield Footer() | Create child widgets for the app. | compose | python | Textualize/textual | tests/snapshot_tests/snapshot_apps/recompose_on_mount.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/snapshot_apps/recompose_on_mount.py | MIT |
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Header()
yield Footer() | Create child widgets for the app. | compose | python | Textualize/textual | tests/snapshot_tests/snapshot_apps/recompose_on_mount.py | https://github.com/Textualize/textual/blob/master/tests/snapshot_tests/snapshot_apps/recompose_on_mount.py | MIT |
async def test_listview_remove_items() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/4735"""
app = ListViewApp()
async with app.run_test() as pilot:
listview = pilot.app.query_one(ListView)
assert len(listview) == 9
await listview.remove_items(range(4, 9))
assert len(listview) == 4 | Regression test for https://github.com/Textualize/textual/issues/4735 | test_listview_remove_items | python | Textualize/textual | tests/listview/test_listview_remove_items.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_listview_remove_items.py | MIT |
async def test_listview_pop_updates_index_and_highlighting(
initial_index, pop_index, expected_new_index, expected_highlighted
) -> None:
"""Regression test for https://github.com/Textualize/textual/issues/5114"""
app = ListViewApp(initial_index)
async with app.run_test() as pilot:
listview = pilot.app.query_one(ListView)
await listview.pop(pop_index)
await pilot.pause()
assert listview.index == expected_new_index
assert listview._nodes[expected_new_index].highlighted is True
assert app.highlighted == expected_highlighted | Regression test for https://github.com/Textualize/textual/issues/5114 | test_listview_pop_updates_index_and_highlighting | python | Textualize/textual | tests/listview/test_listview_remove_items.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_listview_remove_items.py | MIT |
async def test_listview_remove_items_updates_index_and_highlighting(
initial_index, remove_indices, expected_new_index, expected_highlighted
) -> None:
"""Regression test for https://github.com/Textualize/textual/issues/5114"""
app = ListViewApp(initial_index)
async with app.run_test() as pilot:
listview = pilot.app.query_one(ListView)
await listview.remove_items(remove_indices)
await pilot.pause()
assert listview.index == expected_new_index
if expected_new_index is not None:
assert listview._nodes[expected_new_index].highlighted is True
assert app.highlighted == expected_highlighted | Regression test for https://github.com/Textualize/textual/issues/5114 | test_listview_remove_items_updates_index_and_highlighting | python | Textualize/textual | tests/listview/test_listview_remove_items.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_listview_remove_items.py | MIT |
async def test_listview_initial_index(initial_index, expected_index) -> None:
"""Regression test for https://github.com/Textualize/textual/issues/4449"""
class ListViewDisabledItemsApp(App[None]):
def compose(self) -> ComposeResult:
yield ListView(
ListItem(Label("0"), disabled=True),
ListItem(Label("1")),
ListItem(Label("2"), disabled=True),
ListItem(Label("3"), disabled=True),
ListItem(Label("4")),
ListItem(Label("5")),
ListItem(Label("6"), disabled=True),
ListItem(Label("7")),
ListItem(Label("8"), disabled=True),
initial_index=initial_index,
)
app = ListViewDisabledItemsApp()
async with app.run_test() as pilot:
list_view = pilot.app.query_one(ListView)
assert list_view.index == expected_index | Regression test for https://github.com/Textualize/textual/issues/4449 | test_listview_initial_index | python | Textualize/textual | tests/listview/test_listview_initial_index.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_listview_initial_index.py | MIT |
def compose(self) -> ComposeResult:
"""Compose the child widgets."""
for n in range(self._items):
yield ListItem(Label(f"This is item {n}")) | Compose the child widgets. | compose | python | Textualize/textual | tests/listview/test_inherit_listview.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_inherit_listview.py | MIT |
def compose(self) -> ComposeResult:
"""Compose the child widgets."""
yield MyListView(self._items) | Compose the child widgets. | compose | python | Textualize/textual | tests/listview/test_inherit_listview.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_inherit_listview.py | MIT |
async def test_empty_inherited_list_view() -> None:
"""An empty self-populating inherited ListView should work as expected."""
async with ListViewApp().run_test() as pilot:
await pilot.press("tab")
assert pilot.app.query_one(MyListView).index is None
await pilot.press("down")
assert pilot.app.query_one(MyListView).index is None | An empty self-populating inherited ListView should work as expected. | test_empty_inherited_list_view | python | Textualize/textual | tests/listview/test_inherit_listview.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_inherit_listview.py | MIT |
async def test_populated_inherited_list_view() -> None:
"""A self-populating inherited ListView should work as normal."""
async with ListViewApp(30).run_test() as pilot:
await pilot.press("tab")
assert pilot.app.query_one(MyListView).index == 0
await pilot.press("down")
assert pilot.app.query_one(MyListView).index == 1 | A self-populating inherited ListView should work as normal. | test_populated_inherited_list_view | python | Textualize/textual | tests/listview/test_inherit_listview.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_inherit_listview.py | MIT |
async def test_actions_work_when_list_view_empty() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/2265"""
async with ListViewApp().run_test() as pilot:
await pilot.press("tab", "s")
list_view = pilot.app.query_one(MyListView)
assert list_view.action_fired | Regression test for https://github.com/Textualize/textual/issues/2265 | test_actions_work_when_list_view_empty | python | Textualize/textual | tests/listview/test_inherit_listview.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_inherit_listview.py | MIT |
async def test_keyboard_navigation_with_disabled_items() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/3881."""
app = ListViewDisabledItemsApp()
async with app.run_test() as pilot:
for _ in range(5):
await pilot.press("down")
for _ in range(5):
await pilot.press("up")
assert app.highlighted == [
"1",
"4",
"5",
"7",
"5",
"4",
"1",
] | Regression test for https://github.com/Textualize/textual/issues/3881. | test_keyboard_navigation_with_disabled_items | python | Textualize/textual | tests/listview/test_listview_navigation.py | https://github.com/Textualize/textual/blob/master/tests/listview/test_listview_navigation.py | MIT |
async def test_initial_value_is_validated():
"""The initial value should be respected if it is a legal value.
Regression test for https://github.com/Textualize/textual/discussions/3037.
"""
app = SelectApp(1)
async with app.run_test():
assert app.query_one(Select).value == 1 | The initial value should be respected if it is a legal value.
Regression test for https://github.com/Textualize/textual/discussions/3037. | test_initial_value_is_validated | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_value_unknown_option_raises_error():
"""Setting the value to an unknown value raises an error."""
app = SelectApp()
async with app.run_test():
with pytest.raises(InvalidSelectValueError):
app.query_one(Select).value = "french fries" | Setting the value to an unknown value raises an error. | test_value_unknown_option_raises_error | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_initial_value_inside_compose_is_validated():
"""Setting the value to an unknown value inside compose should raise an error."""
class SelectApp(App[None]):
def compose(self):
s = Select[int](SELECT_OPTIONS)
s.value = 73
yield s
app = SelectApp()
with pytest.raises(InvalidSelectValueError):
async with app.run_test():
pass | Setting the value to an unknown value inside compose should raise an error. | test_initial_value_inside_compose_is_validated | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_value_assign_to_blank():
"""Setting the value to BLANK should work with default `allow_blank` value."""
app = SelectApp(1)
async with app.run_test():
select = app.query_one(Select)
assert select.value == 1
select.value = Select.BLANK
assert select.is_blank() | Setting the value to BLANK should work with default `allow_blank` value. | test_value_assign_to_blank | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_initial_value_is_picked_if_allow_blank_is_false():
"""The initial value should be picked by default if allow_blank=False."""
class SelectApp(App[None]):
def compose(self):
yield Select[int](SELECT_OPTIONS, allow_blank=False)
app = SelectApp()
async with app.run_test():
assert app.query_one(Select).value == 0 | The initial value should be picked by default if allow_blank=False. | test_initial_value_is_picked_if_allow_blank_is_false | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_initial_value_is_picked_if_allow_blank_is_false():
"""The initial value should be respected even if allow_blank=False."""
class SelectApp(App[None]):
def compose(self):
yield Select[int](SELECT_OPTIONS, value=2, allow_blank=False)
app = SelectApp()
async with app.run_test():
assert app.query_one(Select).value == 2 | The initial value should be respected even if allow_blank=False. | test_initial_value_is_picked_if_allow_blank_is_false | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_set_value_to_blank_with_allow_blank_false():
"""Setting the value to BLANK with allow_blank=False should raise an error."""
class SelectApp(App[None]):
def compose(self):
yield Select[int](SELECT_OPTIONS, allow_blank=False)
app = SelectApp()
async with app.run_test():
with pytest.raises(InvalidSelectValueError):
app.query_one(Select).value = Select.BLANK | Setting the value to BLANK with allow_blank=False should raise an error. | test_set_value_to_blank_with_allow_blank_false | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_set_options_resets_value_to_blank():
"""Resetting the options should reset the value to BLANK."""
class SelectApp(App[None]):
def compose(self):
yield Select[int](SELECT_OPTIONS, value=2)
app = SelectApp()
async with app.run_test():
select = app.query_one(Select)
assert select.value == 2
select.set_options(MORE_OPTIONS)
assert select.is_blank() | Resetting the options should reset the value to BLANK. | test_set_options_resets_value_to_blank | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_set_options_resets_value_if_allow_blank_is_false():
"""Resetting the options should reset the value if allow_blank=False."""
class SelectApp(App[None]):
def compose(self):
yield Select[int](SELECT_OPTIONS, allow_blank=False)
app = SelectApp()
async with app.run_test():
select = app.query_one(Select)
assert select.value == 0
select.set_options(MORE_OPTIONS)
assert select.value > 2 | Resetting the options should reset the value if allow_blank=False. | test_set_options_resets_value_if_allow_blank_is_false | python | Textualize/textual | tests/select/test_value.py | https://github.com/Textualize/textual/blob/master/tests/select/test_value.py | MIT |
async def test_setting_value_posts_message() -> None:
"""Setting the value of a Select should post a message."""
async with (app := SelectApp()).run_test() as pilot:
assert len(app.changed_messages) == 0
app.query_one(Select).value = 2
await pilot.pause()
assert len(app.changed_messages) == 1 | Setting the value of a Select should post a message. | test_setting_value_posts_message | python | Textualize/textual | tests/select/test_changed_message.py | https://github.com/Textualize/textual/blob/master/tests/select/test_changed_message.py | MIT |
async def test_reactive_prompt_change():
"""Regression test for https://github.com/Textualize/textual/issues/2983"""
class SelectApp(App):
def compose(self):
yield Select[int](
[(str(n), n) for n in range(3)],
prompt="Old prompt",
)
app = SelectApp()
async with app.run_test() as pilot:
select_widget = pilot.app.query_one(Select)
select_current = select_widget.query_one(SelectCurrent)
select_current_label = select_current.query_one("#label", Static)
select_overlay = select_widget.query_one(SelectOverlay)
assert select_current_label.renderable == "Old prompt"
assert select_overlay._options[0].prompt == Text("Old prompt")
select_widget.prompt = "New prompt"
assert select_current_label.renderable == "New prompt"
assert select_overlay._options[0].prompt == Text("New prompt") | Regression test for https://github.com/Textualize/textual/issues/2983 | test_reactive_prompt_change | python | Textualize/textual | tests/select/test_prompt.py | https://github.com/Textualize/textual/blob/master/tests/select/test_prompt.py | MIT |
async def test_option_list_clicking_separator() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/4710"""
app = OptionListApp()
async with app.run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
expected_messages = ["OptionHighlighted"] # Initial highlight
assert option_list.highlighted == 0
assert app.messages == expected_messages
# Select the second option with the mouse
await pilot.click(OptionList, offset=(3, 3))
expected_messages.extend(["OptionHighlighted", "OptionSelected"])
assert option_list.highlighted == 1
assert app.messages == expected_messages
# Click the separator - there should be no change
await pilot.click(OptionList, offset=(3, 2))
assert option_list.highlighted == 1
assert app.messages == expected_messages | Regression test for https://github.com/Textualize/textual/issues/4710 | test_option_list_clicking_separator | python | Textualize/textual | tests/option_list/test_option_list_mouse_click.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_mouse_click.py | MIT |
def compose(self) -> ComposeResult:
"""Compose the child widgets."""
yield OptionList(
*[
Option(str(n), id=str(n), disabled=self.initial_disabled)
for n in range(100)
]
) | Compose the child widgets. | compose | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_default_enabled() -> None:
"""Options created enabled should remain enabled."""
async with OptionListApp(False).run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for option in range(option_list.option_count):
assert option_list.get_option_at_index(option).disabled is False | Options created enabled should remain enabled. | test_default_enabled | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_default_disabled() -> None:
"""Options created disabled should remain disabled."""
async with OptionListApp(True).run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for option in range(option_list.option_count):
assert option_list.get_option_at_index(option).disabled is True | Options created disabled should remain disabled. | test_default_disabled | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_enabled_to_disabled_via_index() -> None:
"""It should be possible to change enabled to disabled via index."""
async with OptionListApp(False).run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for n in range(option_list.option_count):
assert option_list.get_option_at_index(n).disabled is False
option_list.disable_option_at_index(n)
assert option_list.get_option_at_index(n).disabled is True | It should be possible to change enabled to disabled via index. | test_enabled_to_disabled_via_index | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_disabled_to_enabled_via_index() -> None:
"""It should be possible to change disabled to enabled via index."""
async with OptionListApp(True).run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for n in range(option_list.option_count):
assert option_list.get_option_at_index(n).disabled is True
option_list.enable_option_at_index(n)
assert option_list.get_option_at_index(n).disabled is False | It should be possible to change disabled to enabled via index. | test_disabled_to_enabled_via_index | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_enabled_to_disabled_via_id() -> None:
"""It should be possible to change enabled to disabled via id."""
async with OptionListApp(False).run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for n in range(option_list.option_count):
assert option_list.get_option(str(n)).disabled is False
option_list.disable_option(str(n))
assert option_list.get_option(str(n)).disabled is True | It should be possible to change enabled to disabled via id. | test_enabled_to_disabled_via_id | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_disabled_to_enabled_via_id() -> None:
"""It should be possible to change disabled to enabled via id."""
async with OptionListApp(True).run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for n in range(option_list.option_count):
assert option_list.get_option(str(n)).disabled is True
option_list.enable_option(str(n))
assert option_list.get_option(str(n)).disabled is False | It should be possible to change disabled to enabled via id. | test_disabled_to_enabled_via_id | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_disable_invalid_id() -> None:
"""Disabling an option via an ID that does not exist should throw an error."""
async with OptionListApp(True).run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
pilot.app.query_one(OptionList).disable_option("does-not-exist") | Disabling an option via an ID that does not exist should throw an error. | test_disable_invalid_id | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_disable_invalid_index() -> None:
"""Disabling an option via an index that does not exist should throw an error."""
async with OptionListApp(True).run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
pilot.app.query_one(OptionList).disable_option_at_index(4242) | Disabling an option via an index that does not exist should throw an error. | test_disable_invalid_index | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_enable_invalid_id() -> None:
"""Disabling an option via an ID that does not exist should throw an error."""
async with OptionListApp(False).run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
pilot.app.query_one(OptionList).enable_option("does-not-exist") | Disabling an option via an ID that does not exist should throw an error. | test_enable_invalid_id | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_enable_invalid_index() -> None:
"""Disabling an option via an index that does not exist should throw an error."""
async with OptionListApp(False).run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
pilot.app.query_one(OptionList).enable_option_at_index(4242) | Disabling an option via an index that does not exist should throw an error. | test_enable_invalid_index | python | Textualize/textual | tests/option_list/test_option_list_disabled.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_disabled.py | MIT |
async def test_option_list_with_subclassed_options() -> None:
"""It should be possible to build an option list with subclassed options."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 100
for n in range(option_list.option_count):
for option in (
option_list.get_option(str(n)),
option_list.get_option_at_index(n),
):
assert isinstance(option, OptionWithExtras)
assert option.prompt == str(n)
assert option.id == str(n)
assert option.test == n | It should be possible to build an option list with subclassed options. | test_option_list_with_subclassed_options | python | Textualize/textual | tests/option_list/test_option_list_option_subclass.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_option_subclass.py | MIT |
async def test_all_parameters_become_options() -> None:
"""All input parameters to a list should become options."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 5
for n in range(5):
assert isinstance(option_list.get_option_at_index(n), Option) | All input parameters to a list should become options. | test_all_parameters_become_options | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_id_capture() -> None:
"""All options given an ID should retain the ID."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
with_id = 0
without_id = 0
for n in range(5):
if option_list.get_option_at_index(n).id is None:
without_id += 1
else:
with_id += 1
assert with_id == 2
assert without_id == 3 | All options given an ID should retain the ID. | test_id_capture | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_get_option_by_id() -> None:
"""It should be possible to get an option by ID."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.get_option("3").prompt == "3"
assert option_list.get_option("4").prompt == "4" | It should be possible to get an option by ID. | test_get_option_by_id | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_get_option_with_bad_id() -> None:
"""Asking for an option with a bad ID should give an error."""
async with OptionListApp().run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
_ = pilot.app.query_one(OptionList).get_option("this does not exist") | Asking for an option with a bad ID should give an error. | test_get_option_with_bad_id | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_get_option_by_index() -> None:
"""It should be possible to get an option by index."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for n in range(5):
assert option_list.get_option_at_index(n).prompt == str(n)
assert option_list.get_option_at_index(-1).prompt == "4" | It should be possible to get an option by index. | test_get_option_by_index | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_get_option_at_bad_index() -> None:
"""Asking for an option at a bad index should give an error."""
async with OptionListApp().run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
_ = pilot.app.query_one(OptionList).get_option_at_index(42)
with pytest.raises(OptionDoesNotExist):
_ = pilot.app.query_one(OptionList).get_option_at_index(-42) | Asking for an option at a bad index should give an error. | test_get_option_at_bad_index | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_clear_option_list() -> None:
"""It should be possible to clear the option list of all content."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 5
option_list.clear_options()
assert option_list.option_count == 0 | It should be possible to clear the option list of all content. | test_clear_option_list | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_add_later() -> None:
"""It should be possible to add more items to a list."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 5
option_list.add_option("more")
assert option_list.option_count == 6
option_list.add_option()
assert option_list.option_count == 6
option_list.add_option(Option("even more"))
assert option_list.option_count == 7
option_list.add_options(
[Option("more still"), "Yet more options", "so many options!"]
)
assert option_list.option_count == 10
option_list.add_option(None)
assert option_list.option_count == 10
option_list.add_options([])
assert option_list.option_count == 10 | It should be possible to add more items to a list. | test_add_later | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_create_with_duplicate_id() -> None:
"""Adding an option with a duplicate ID should be an error."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 5
with pytest.raises(DuplicateID):
option_list.add_option(Option("dupe", id="3"))
assert option_list.option_count == 5 | Adding an option with a duplicate ID should be an error. | test_create_with_duplicate_id | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_create_with_duplicate_id_and_subsequent_non_dupes() -> None:
"""Adding an option with a duplicate ID should be an error."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 5
with pytest.raises(DuplicateID):
option_list.add_option(Option("dupe", id="3"))
assert option_list.option_count == 5
option_list.add_option(Option("Not a dupe", id="6"))
assert option_list.option_count == 6
option_list.add_option(Option("Not a dupe", id="7"))
assert option_list.option_count == 7 | Adding an option with a duplicate ID should be an error. | test_create_with_duplicate_id_and_subsequent_non_dupes | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_adding_multiple_duplicates_at_once() -> None:
"""Adding duplicates together than aren't existing duplicates should be an error."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 5
with pytest.raises(DuplicateID):
option_list.add_options(
[
Option("dupe", id="42"),
Option("dupe", id="42"),
]
)
assert option_list.option_count == 5 | Adding duplicates together than aren't existing duplicates should be an error. | test_adding_multiple_duplicates_at_once | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_options_are_available_soon() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/3903."""
option = Option("", id="some_id")
option_list = OptionList(option)
assert option_list.get_option("some_id") is option | Regression test for https://github.com/Textualize/textual/issues/3903. | test_options_are_available_soon | python | Textualize/textual | tests/option_list/test_option_list_create.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_create.py | MIT |
async def test_initial_highlight() -> None:
"""The highlight should start on the first item."""
async with OptionListApp().run_test() as pilot:
assert pilot.app.query_one(OptionList).highlighted == 0 | The highlight should start on the first item. | test_initial_highlight | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_cleared_highlight_is_none() -> None:
"""The highlight should be `None` if the list is cleared."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
option_list.clear_options()
assert option_list.highlighted is None | The highlight should be `None` if the list is cleared. | test_cleared_highlight_is_none | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_cleared_movement_does_nothing() -> None:
"""The highlight should remain `None` if the list is cleared."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
option_list.clear_options()
assert option_list.highlighted is None
await pilot.press("tab", "down", "up", "pagedown", "pageup", "home", "end")
assert option_list.highlighted is None | The highlight should remain `None` if the list is cleared. | test_cleared_movement_does_nothing | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_move_down() -> None:
"""The highlight should move down when asked to."""
async with OptionListApp().run_test() as pilot:
await pilot.press("tab", "down")
assert pilot.app.query_one(OptionList).highlighted == 1 | The highlight should move down when asked to. | test_move_down | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_move_down_from_end() -> None:
"""The highlight should wrap around when moving down from the end."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
option_list.highlighted = 5
await pilot.press("tab", "down")
assert option_list.highlighted == 0 | The highlight should wrap around when moving down from the end. | test_move_down_from_end | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_move_up() -> None:
"""The highlight should move up when asked to."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
option_list.highlighted = 1
await pilot.press("tab", "up")
assert option_list.highlighted == 0 | The highlight should move up when asked to. | test_move_up | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_move_up_from_nowhere() -> None:
"""The highlight should settle on the last item when moving up from `None`."""
async with OptionListApp().run_test() as pilot:
await pilot.press("tab", "up")
assert pilot.app.query_one(OptionList).highlighted == 5 | The highlight should settle on the last item when moving up from `None`. | test_move_up_from_nowhere | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_move_end() -> None:
"""The end key should go to the end of the list."""
async with OptionListApp().run_test() as pilot:
await pilot.press("tab", "end")
assert pilot.app.query_one(OptionList).highlighted == 5 | The end key should go to the end of the list. | test_move_end | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_move_home() -> None:
"""The home key should go to the start of the list."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.highlighted == 0
option_list.highlighted = 5
assert option_list.highlighted == 5
await pilot.press("tab", "home")
assert option_list.highlighted == 0 | The home key should go to the start of the list. | test_move_home | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_page_down_from_start_short_list() -> None:
"""Doing a page down from the start of a short list should move to the end."""
async with OptionListApp().run_test() as pilot:
await pilot.press("tab", "pagedown")
assert pilot.app.query_one(OptionList).highlighted == 5 | Doing a page down from the start of a short list should move to the end. | test_page_down_from_start_short_list | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_page_up_from_end_short_list() -> None:
"""Doing a page up from the end of a short list should move to the start."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.highlighted == 0
option_list.highlighted = 5
assert option_list.highlighted == 5
await pilot.press("tab", "pageup")
assert option_list.highlighted == 0 | Doing a page up from the end of a short list should move to the start. | test_page_up_from_end_short_list | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_page_down_from_end_short_list() -> None:
"""Doing a page down from the end of a short list should go nowhere."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.highlighted == 0
option_list.highlighted = 5
assert option_list.highlighted == 5
await pilot.press("tab", "pagedown")
assert option_list.highlighted == 5 | Doing a page down from the end of a short list should go nowhere. | test_page_down_from_end_short_list | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_page_up_from_start_short_list() -> None:
"""Doing a page up from the start of a short list go nowhere."""
async with OptionListApp().run_test() as pilot:
await pilot.press("tab", "pageup")
assert pilot.app.query_one(OptionList).highlighted == 0 | Doing a page up from the start of a short list go nowhere. | test_page_up_from_start_short_list | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_empty_list_movement() -> None:
"""Attempting to move around an empty list should be a non-operation."""
async with EmptyOptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
await pilot.press("tab")
for movement in ("up", "down", "home", "end", "pageup", "pagedown"):
await pilot.press(movement)
assert option_list.highlighted is None | Attempting to move around an empty list should be a non-operation. | test_empty_list_movement | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_no_highlight_movement(movement: str, landing: int) -> None:
"""Attempting to move around in a list with no highlight should select the most appropriate item."""
async with EmptyOptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
for _ in range(100):
option_list.add_option("test")
await pilot.press("tab")
await pilot.press(movement)
assert option_list.highlighted == landing | Attempting to move around in a list with no highlight should select the most appropriate item. | test_no_highlight_movement | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_keyboard_navigation_with_disabled_options() -> None:
"""Regression test for https://github.com/Textualize/textual/issues/3881."""
app = OptionListDisabledOptionsApp()
async with app.run_test() as pilot:
for _ in range(5):
await pilot.press("down")
for _ in range(5):
await pilot.press("up")
assert app.highlighted == [
"1",
"4",
"5",
"7",
"1",
"4",
"1",
"7",
"5",
"4",
"1",
] | Regression test for https://github.com/Textualize/textual/issues/3881. | test_keyboard_navigation_with_disabled_options | python | Textualize/textual | tests/option_list/test_option_list_movement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_movement.py | MIT |
async def test_remove_first_option_via_index() -> None:
"""It should be possible to remove the first option of an option list, via index."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 2
assert option_list.highlighted == 0
option_list.remove_option_at_index(0)
assert option_list.option_count == 1
assert option_list.highlighted == 0 | It should be possible to remove the first option of an option list, via index. | test_remove_first_option_via_index | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_first_option_via_id() -> None:
"""It should be possible to remove the first option of an option list, via ID."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 2
assert option_list.highlighted == 0
option_list.remove_option("0")
assert option_list.option_count == 1
assert option_list.highlighted == 0 | It should be possible to remove the first option of an option list, via ID. | test_remove_first_option_via_id | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_last_option_via_index() -> None:
"""It should be possible to remove the last option of an option list, via index."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 2
assert option_list.highlighted == 0
option_list.remove_option_at_index(1)
assert option_list.option_count == 1
assert option_list.highlighted == 0 | It should be possible to remove the last option of an option list, via index. | test_remove_last_option_via_index | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_last_option_via_id() -> None:
"""It should be possible to remove the last option of an option list, via ID."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 2
assert option_list.highlighted == 0
option_list.remove_option("1")
assert option_list.option_count == 1
assert option_list.highlighted == 0 | It should be possible to remove the last option of an option list, via ID. | test_remove_last_option_via_id | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_all_options_via_index() -> None:
"""It should be possible to remove all options via index."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 2
assert option_list.highlighted == 0
option_list.remove_option_at_index(0)
option_list.remove_option_at_index(0)
assert option_list.option_count == 0
assert option_list.highlighted is None | It should be possible to remove all options via index. | test_remove_all_options_via_index | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_all_options_via_id() -> None:
"""It should be possible to remove all options via ID."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
assert option_list.option_count == 2
assert option_list.highlighted == 0
option_list.remove_option("0")
option_list.remove_option("1")
assert option_list.option_count == 0
assert option_list.highlighted is None | It should be possible to remove all options via ID. | test_remove_all_options_via_id | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_invalid_id() -> None:
"""Attempting to remove an option ID that doesn't exist should raise an exception."""
async with OptionListApp().run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
pilot.app.query_one(OptionList).remove_option("does-not-exist") | Attempting to remove an option ID that doesn't exist should raise an exception. | test_remove_invalid_id | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_invalid_index() -> None:
"""Attempting to remove an option index that doesn't exist should raise an exception."""
async with OptionListApp().run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
pilot.app.query_one(OptionList).remove_option_at_index(23) | Attempting to remove an option index that doesn't exist should raise an exception. | test_remove_invalid_index | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_remove_with_hover_on_last_option():
"""https://github.com/Textualize/textual/issues/3270"""
async with OptionListApp().run_test() as pilot:
await pilot.hover(OptionList, Offset(1, 1) + Offset(2, 1))
option_list = pilot.app.query_one(OptionList)
assert option_list._mouse_hovering_over == 1
option_list.remove_option_at_index(0)
assert option_list._mouse_hovering_over == None | https://github.com/Textualize/textual/issues/3270 | test_remove_with_hover_on_last_option | python | Textualize/textual | tests/option_list/test_option_removal.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_removal.py | MIT |
async def test_get_after_add() -> None:
"""It should be possible to get an option by ID after adding."""
async with OptionListApp().run_test() as pilot:
option_list = pilot.app.query_one(OptionList)
option_list.add_option(Option("0", id="0"))
assert option_list.get_option("0").id == "0" | It should be possible to get an option by ID after adding. | test_get_after_add | python | Textualize/textual | tests/option_list/test_option_list_id_stability.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_id_stability.py | MIT |
async def test_messages_on_startup() -> None:
"""There should be a highlighted message when a non-empty option list first starts up."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
await pilot.pause()
assert pilot.app.messages == [("OptionHighlighted", "0", 0)] | There should be a highlighted message when a non-empty option list first starts up. | test_messages_on_startup | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_same_highlight_message() -> None:
"""Highlighting a highlight should result in no message."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
await pilot.pause()
pilot.app.query_one(OptionList).highlighted = 0
await pilot.pause()
assert pilot.app.messages == [("OptionHighlighted", "0", 0)] | Highlighting a highlight should result in no message. | test_same_highlight_message | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_highlight_disabled_option_no_message() -> None:
"""Highlighting a disabled option should result in no messages."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
await pilot.pause()
pilot.app.query_one(OptionList).disable_option("1")
pilot.app.query_one(OptionList).highlighted = 1
await pilot.pause()
assert pilot.app.messages[1:] == [] | Highlighting a disabled option should result in no messages. | test_highlight_disabled_option_no_message | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_new_highlight() -> None:
"""Setting the highlight to a new option should result in a message."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
await pilot.pause()
pilot.app.query_one(OptionList).highlighted = 2
await pilot.pause()
assert pilot.app.messages[1:] == [("OptionHighlighted", "2", 2)] | Setting the highlight to a new option should result in a message. | test_new_highlight | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_move_highlight_with_keyboard() -> None:
"""Changing option via the keyboard should result in a message."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
await pilot.press("tab", "down")
assert pilot.app.messages[1:] == [("OptionHighlighted", "1", 1)] | Changing option via the keyboard should result in a message. | test_move_highlight_with_keyboard | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_select_message_with_keyboard() -> None:
"""Hitting enter on an option should result in a message."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
await pilot.press("tab", "down", "enter")
assert pilot.app.messages[1:] == [
("OptionHighlighted", "1", 1),
("OptionSelected", "1", 1),
] | Hitting enter on an option should result in a message. | test_select_message_with_keyboard | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_click_option_with_mouse() -> None:
"""Clicking on an option via the mouse should result in highlight and select messages."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
await pilot.click(OptionList, Offset(2, 2))
assert pilot.app.messages[1:] == [
("OptionHighlighted", "1", 1),
("OptionSelected", "1", 1),
] | Clicking on an option via the mouse should result in highlight and select messages. | test_click_option_with_mouse | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_click_disabled_option_with_mouse() -> None:
"""Clicking on a disabled option via the mouse should result no messages."""
async with OptionListApp().run_test() as pilot:
assert isinstance(pilot.app, OptionListApp)
pilot.app.query_one(OptionList).disable_option("1")
await pilot.click(OptionList, Offset(1, 1))
assert pilot.app.messages[1:] == [] | Clicking on a disabled option via the mouse should result no messages. | test_click_disabled_option_with_mouse | python | Textualize/textual | tests/option_list/test_option_messages.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_messages.py | MIT |
async def test_no_hover() -> None:
"""When the mouse isn't over the OptionList _mouse_hovering_over should be None."""
async with OptionListApp().run_test() as pilot:
await pilot.hover(Label)
assert pilot.app.query_one(OptionList)._mouse_hovering_over is None | When the mouse isn't over the OptionList _mouse_hovering_over should be None. | test_no_hover | python | Textualize/textual | tests/option_list/test_option_list_mouse_hover.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_mouse_hover.py | MIT |
async def test_hover_highlight() -> None:
"""The mouse hover value should react to the mouse hover over a highlighted option."""
async with OptionListApp().run_test() as pilot:
await pilot.hover(OptionList, Offset(2, 1))
option_list = pilot.app.query_one(OptionList)
assert option_list._mouse_hovering_over == 0
assert option_list._mouse_hovering_over == option_list.highlighted | The mouse hover value should react to the mouse hover over a highlighted option. | test_hover_highlight | python | Textualize/textual | tests/option_list/test_option_list_mouse_hover.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_mouse_hover.py | MIT |
async def test_hover_no_highlight() -> None:
"""The mouse hover value should react to the mouse hover over a non-highlighted option."""
async with OptionListApp().run_test() as pilot:
await pilot.hover(OptionList, Offset(1, 1) + Offset(2, 1))
option_list = pilot.app.query_one(OptionList)
assert option_list._mouse_hovering_over == 1
assert option_list._mouse_hovering_over != option_list.highlighted | The mouse hover value should react to the mouse hover over a non-highlighted option. | test_hover_no_highlight | python | Textualize/textual | tests/option_list/test_option_list_mouse_hover.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_mouse_hover.py | MIT |
async def test_hover_disabled() -> None:
"""The mouse hover value should react to the mouse hover over a disabled option."""
async with OptionListApp().run_test() as pilot:
await pilot.hover(OptionList, Offset(1, 3) + Offset(2, 1))
option_list = pilot.app.query_one(OptionList)
assert option_list._mouse_hovering_over == 3
assert option_list.get_option_at_index(
option_list._mouse_hovering_over
).disabled
assert option_list._mouse_hovering_over != option_list.highlighted | The mouse hover value should react to the mouse hover over a disabled option. | test_hover_disabled | python | Textualize/textual | tests/option_list/test_option_list_mouse_hover.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_mouse_hover.py | MIT |
async def test_hover_then_leave() -> None:
"""After a mouse has been over an OptionList and left _mouse_hovering_over should be None again."""
async with OptionListApp().run_test() as pilot:
await pilot.hover(OptionList, Offset(2, 1))
option_list = pilot.app.query_one(OptionList)
assert option_list._mouse_hovering_over == 0
await pilot.hover(Label)
assert option_list._mouse_hovering_over is None | After a mouse has been over an OptionList and left _mouse_hovering_over should be None again. | test_hover_then_leave | python | Textualize/textual | tests/option_list/test_option_list_mouse_hover.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_list_mouse_hover.py | MIT |
async def test_replace_option_prompt_with_invalid_id() -> None:
"""Attempting to replace the prompt of an option ID that doesn't exist should raise an exception."""
async with OptionListApp().run_test() as pilot:
with pytest.raises(OptionDoesNotExist):
pilot.app.query_one(OptionList).replace_option_prompt("does-not-exist", "new-prompt") | Attempting to replace the prompt of an option ID that doesn't exist should raise an exception. | test_replace_option_prompt_with_invalid_id | python | Textualize/textual | tests/option_list/test_option_prompt_replacement.py | https://github.com/Textualize/textual/blob/master/tests/option_list/test_option_prompt_replacement.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.