Merge branch 'main' into tree-node-children-prop

This commit is contained in:
Dave Pearson
2023-01-06 06:18:15 +00:00
6 changed files with 56 additions and 8 deletions

View File

@@ -2,13 +2,8 @@ import pytest
from textual.widgets import Tree, TreeNode
def label_of(node: TreeNode[None]):
"""Get the label of a node.
TODO: This is just a helper function to reduce the number of type
errors, which can and will be remove once this code is merged with a
version of main that also has the TreeNode.label PR merged.
"""
return str(node._label)
"""Get the label of a node as a string"""
return str(node.label)
def test_tree_node_children() -> None:

View File

@@ -0,0 +1,17 @@
from textual.widgets import Tree, TreeNode
from rich.text import Text
def test_tree_node_label() -> None:
"""It should be possible to modify a TreeNode's label."""
node = TreeNode(Tree[None]("Xenomorph Lifecycle"), None, 0, "Facehugger")
assert node.label == Text("Facehugger")
node.label = "Chestbuster"
assert node.label == Text("Chestbuster")
def test_tree_node_label_via_tree() -> None:
"""It should be possible to modify a TreeNode's label when created via a Tree."""
tree = Tree[None]("Xenomorph Lifecycle")
node = tree.root.add("Facehugger")
assert node.label == Text("Facehugger")
node.label = "Chestbuster"
assert node.label == Text("Chestbuster")