Skip to content

Commit

Permalink
Node_Info error if node does not exist
Browse files Browse the repository at this point in the history
closes #5
  • Loading branch information
dhimmel committed Dec 23, 2020
1 parent 2bf6579 commit fa2ea18
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nxontology/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ class Node_Info(Freezable):
"""

def __init__(self, nxo: NXOntology, node: Node):
if node not in nxo.graph:
raise NodeNotFound(f"{node} not in graph.")
self.nxo = nxo
self.node = node

Expand Down
5 changes: 5 additions & 0 deletions nxontology/tests/ontology_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def test_node_info_gold(metal_nxo_frozen: NXOntology) -> None:
assert gold_info.n_ancestors == 4


def test_node_info_not_found(metal_nxo_frozen: NXOntology) -> None:
with pytest.raises(NodeNotFound, match="not-a-metal not in graph"):
metal_nxo_frozen.node_info("not-a-metal")


def test_intrinsic_ic_unscaled(metal_nxo_frozen: NXOntology) -> None:
assert metal_nxo_frozen.n_nodes == 8
# number of descendants per node including self
Expand Down

0 comments on commit fa2ea18

Please sign in to comment.