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:
Dave Pearson
2023-03-30 11:20:17 +01:00
committed by GitHub
parent 87f96ef8a1
commit 0a9b9603a0
2 changed files with 48 additions and 2 deletions

View File

@@ -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]):
@@ -83,3 +85,17 @@ async def test_remove_all_options_via_id() -> None:
option_list.remove_option("1")
assert option_list.option_count == 0
assert option_list.highlighted is None
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")
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)