|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import pytest |
| 6 | + |
5 | 7 | from textual.app import App, ComposeResult |
6 | 8 | from textual.widgets import OptionList |
7 | | -from textual.widgets.option_list import Option |
| 9 | +from textual.widgets.option_list import Option, OptionDoesNotExist |
8 | 10 |
|
9 | 11 |
|
10 | 12 | class OptionListApp(App[None]): |
@@ -78,3 +80,31 @@ async def test_disabled_to_enabled_via_id() -> None: |
78 | 80 | assert option_list.get_option(str(n)).disabled is True |
79 | 81 | option_list.enable_option(str(n)) |
80 | 82 | assert option_list.get_option(str(n)).disabled is False |
| 83 | + |
| 84 | + |
| 85 | +async def test_disable_invalid_id() -> None: |
| 86 | + """Disabling an option via an ID that does not exist should throw an error.""" |
| 87 | + async with OptionListApp(True).run_test() as pilot: |
| 88 | + with pytest.raises(OptionDoesNotExist): |
| 89 | + pilot.app.query_one(OptionList).disable_option("does-not-exist") |
| 90 | + |
| 91 | + |
| 92 | +async def test_disable_invalid_index() -> None: |
| 93 | + """Disabling an option via an index that does not exist should throw an error.""" |
| 94 | + async with OptionListApp(True).run_test() as pilot: |
| 95 | + with pytest.raises(OptionDoesNotExist): |
| 96 | + pilot.app.query_one(OptionList).disable_option_at_index(4242) |
| 97 | + |
| 98 | + |
| 99 | +async def test_enable_invalid_id() -> None: |
| 100 | + """Disabling an option via an ID that does not exist should throw an error.""" |
| 101 | + async with OptionListApp(False).run_test() as pilot: |
| 102 | + with pytest.raises(OptionDoesNotExist): |
| 103 | + pilot.app.query_one(OptionList).enable_option("does-not-exist") |
| 104 | + |
| 105 | + |
| 106 | +async def test_enable_invalid_index() -> None: |
| 107 | + """Disabling an option via an index that does not exist should throw an error.""" |
| 108 | + async with OptionListApp(False).run_test() as pilot: |
| 109 | + with pytest.raises(OptionDoesNotExist): |
| 110 | + pilot.app.query_one(OptionList).enable_option_at_index(4242) |
0 commit comments