mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #2508 from davep/add-options
Add `add_options` to `OptionList`
This commit is contained in:
@@ -106,6 +106,14 @@ async def test_add_later() -> None:
|
||||
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
|
||||
|
||||
|
||||
async def test_create_with_duplicate_id() -> None:
|
||||
|
||||
File diff suppressed because one or more lines are too long
45
tests/snapshot_tests/snapshot_apps/option_list.py
Normal file
45
tests/snapshot_tests/snapshot_apps/option_list.py
Normal file
@@ -0,0 +1,45 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from rich.text import Text
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.containers import Horizontal
|
||||
from textual.widgets import OptionList
|
||||
from textual.widgets.option_list import Option
|
||||
|
||||
|
||||
class OptionListApp(App[None]):
|
||||
|
||||
def compose( self ) -> ComposeResult:
|
||||
with Horizontal():
|
||||
yield OptionList(
|
||||
"One",
|
||||
Option("Two"),
|
||||
None,
|
||||
Text.from_markup("[red]Three[/]")
|
||||
)
|
||||
yield OptionList(id="later-individual")
|
||||
yield OptionList(id="later-at-once")
|
||||
|
||||
def on_mount(self) -> None:
|
||||
options: list[None | str | Text | Option] = [
|
||||
"One",
|
||||
Option("Two"),
|
||||
None,
|
||||
Text.from_markup("[red]Three[/]"),
|
||||
]
|
||||
option_list = self.query_one("#later-individual", OptionList)
|
||||
for option in options:
|
||||
option_list.add_option(option)
|
||||
option_list.highlighted = 0
|
||||
option_list = self.query_one("#later-at-once", OptionList)
|
||||
option_list.add_options([
|
||||
"One",
|
||||
Option("Two"),
|
||||
None,
|
||||
Text.from_markup("[red]Three[/]"),
|
||||
])
|
||||
option_list.highlighted = 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
OptionListApp().run()
|
||||
@@ -203,6 +203,8 @@ def test_option_list(snap_compare):
|
||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_options.py")
|
||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "option_list_tables.py")
|
||||
|
||||
def test_option_list_build(snap_compare):
|
||||
assert snap_compare(SNAPSHOT_APPS_DIR / "option_list.py")
|
||||
|
||||
def test_progress_bar_indeterminate(snap_compare):
|
||||
assert snap_compare(WIDGET_EXAMPLES_DIR / "progress_bar_isolated_.py", press=["f"])
|
||||
|
||||
Reference in New Issue
Block a user