Skip to content

Commit

Permalink
add tests form pydata#9494 but at NamedNode level
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Sep 16, 2024
1 parent f1b2b31 commit 9e2bce7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions xarray/tests/test_treenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,28 @@ def test_node_names(self):
with pytest.raises(TypeError, match="must be a string or None"):
NamedNode(name=0)

def test_names(self):
nn = NamedNode()
assert nn.name is None

nn = NamedNode(name="foo")
assert nn.name == "foo"

nn.name = "bar"
assert nn.name == "bar"

nn = NamedNode(children={"foo": NamedNode()})
assert nn.children["foo"].name == "foo"
with pytest.raises(
ValueError, match="cannot set the name of a node which already has a parent"
):
nn.children["foo"].name = "bar"

detached = nn.children["foo"].copy()
assert detached.name == "foo"
detached.name = "bar"
assert detached.name == "bar"


def create_test_tree() -> tuple[NamedNode, NamedNode]:
# a
Expand Down

0 comments on commit 9e2bce7

Please sign in to comment.