Run black over recent Tree tests

Now that we're running black on tests...
This commit is contained in:
Dave Pearson
2023-01-07 09:30:01 +00:00
parent c7cb525a6a
commit ea8252cfcc
3 changed files with 13 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import pytest import pytest
from textual.widgets import Tree, TreeNode from textual.widgets import Tree, TreeNode
def label_of(node: TreeNode[None]): def label_of(node: TreeNode[None]):
"""Get the label of a node as a string""" """Get the label of a node as a string"""
return str(node.label) return str(node.label)
@@ -8,17 +9,21 @@ def label_of(node: TreeNode[None]):
def test_tree_node_children() -> None: def test_tree_node_children() -> None:
"""A node's children property should act like an immutable list.""" """A node's children property should act like an immutable list."""
CHILDREN=23 CHILDREN = 23
tree = Tree[None]("Root") tree = Tree[None]("Root")
for child in range(CHILDREN): for child in range(CHILDREN):
tree.root.add(str(child)) tree.root.add(str(child))
assert len(tree.root.children)==CHILDREN assert len(tree.root.children) == CHILDREN
for child in range(CHILDREN): for child in range(CHILDREN):
assert label_of(tree.root.children[child]) == str(child) assert label_of(tree.root.children[child]) == str(child)
assert label_of(tree.root.children[0]) == "0" assert label_of(tree.root.children[0]) == "0"
assert label_of(tree.root.children[-1]) == str(CHILDREN-1) assert label_of(tree.root.children[-1]) == str(CHILDREN - 1)
assert [label_of(node) for node in tree.root.children] == [str(n) for n in range(CHILDREN)] assert [label_of(node) for node in tree.root.children] == [
assert [label_of(node) for node in tree.root.children[:2]] == [str(n) for n in range(2)] str(n) for n in range(CHILDREN)
]
assert [label_of(node) for node in tree.root.children[:2]] == [
str(n) for n in range(2)
]
with pytest.raises(TypeError): with pytest.raises(TypeError):
tree.root.children[0] = tree.root.children[1] tree.root.children[0] = tree.root.children[1]
with pytest.raises(TypeError): with pytest.raises(TypeError):

View File

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

View File

@@ -1,5 +1,6 @@
from textual.widgets import TreeNode, Tree from textual.widgets import TreeNode, Tree
def test_tree_node_parent() -> None: def test_tree_node_parent() -> None:
"""It should be possible to access a TreeNode's parent.""" """It should be possible to access a TreeNode's parent."""
tree = Tree[None]("Anakin") tree = Tree[None]("Anakin")