Add an _index method to NodeList

This maps on to a normal List.index.
This commit is contained in:
Dave Pearson
2022-11-01 10:55:15 +00:00
parent 294166cfec
commit cee69fbc32
2 changed files with 25 additions and 0 deletions

View File

@@ -1,3 +1,5 @@
import pytest
from textual.widget import Widget
from textual._node_list import NodeList
@@ -35,6 +37,15 @@ def test_contains():
assert widget in nodes
assert Widget() not in nodes
def test_index():
"""Can we get the index of a widget in the list?"""
widget = Widget()
nodes = NodeList()
with pytest.raises(ValueError):
_ = nodes._index(widget)
nodes._append(widget)
assert nodes._index(widget) == 0
def test_remove():
"""Can we remove a widget we've added?"""
widget = Widget()