File: test_tree_get_node_by_id.py

package info (click to toggle)
textual 2.1.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,080 kB
  • sloc: python: 85,423; lisp: 1,669; makefile: 101
file content (18 lines) | stat: -rw-r--r-- 620 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from typing import cast

import pytest

from textual.widgets import Tree
from textual.widgets.tree import NodeID, UnknownNodeID


def test_get_tree_node_by_id() -> None:
    """It should be possible to get a TreeNode by its ID."""
    tree = Tree[None]("Anakin")
    child = tree.root.add("Leia")
    grandchild = child.add("Ben")
    assert tree.get_node_by_id(tree.root.id).id == tree.root.id
    assert tree.get_node_by_id(child.id).id == child.id
    assert tree.get_node_by_id(grandchild.id).id == grandchild.id
    with pytest.raises(UnknownNodeID):
        tree.get_node_by_id(cast(NodeID, grandchild.id + 1000))