mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Extend OptionList testing (#2166)
* Add tests for errors when removing things that don't exist * Add tests for errors when toggling enabled/disabled on invalid options
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import OptionList
|
||||
from textual.widgets.option_list import Option
|
||||
from textual.widgets.option_list import Option, OptionDoesNotExist
|
||||
|
||||
|
||||
class OptionListApp(App[None]):
|
||||
@@ -78,3 +80,31 @@ async def test_disabled_to_enabled_via_id() -> None:
|
||||
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
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user