raise value error if nuc not found

This commit is contained in:
shimwell 2026-04-05 11:00:03 +02:00
parent 2ca0fafea0
commit 42696ed4ef
2 changed files with 13 additions and 3 deletions

View file

@ -1251,7 +1251,17 @@ class Chain:
Names of all radioactive decay daughters reachable from the
parent.
Raises
------
ValueError
If the nuclide is not present in the chain.
"""
if nuclide not in self.nuclide_dict:
raise ValueError(
f"Cannot find decay daughters for '{nuclide}': "
"nuclide is not in the chain."
)
daughters = set()
stack = [nuclide]
visited = set()

View file

@ -607,9 +607,9 @@ def test_get_decay_daughters(gnd_simple_chain):
daughters = gnd_simple_chain.get_decay_daughters("Cs135")
assert daughters == set()
# Nuclide not in chain returns empty set
daughters = gnd_simple_chain.get_decay_daughters("Xx999")
assert daughters == set()
# Nuclide not in chain raises ValueError
with pytest.raises(ValueError, match="not in the chain"):
gnd_simple_chain.get_decay_daughters("Xx999")
def test_get_decay_daughters_cyclic(simple_chain):