Provide better error message if missing FPY parent is not in chain

This commit is contained in:
Paul Romano 2020-06-17 07:08:49 -05:00
parent 3c25a2a4b3
commit 5e8c7a55fe
2 changed files with 25 additions and 0 deletions

View file

@ -218,9 +218,16 @@ class Nuclide:
# Check for use of FPY from other nuclide
parent = fpy_elem.get('parent')
if parent is not None:
assert root is not None
fpy_elem = root.find(
'.//nuclide[@name="{}"]/neutron_fission_yields'.format(parent)
)
if fpy_elem is None:
raise ValueError(
"Fission product yields for {0} borrow from {1}, but {1} is"
" not present in the chain file or has no yields.".format(
nuc.name, parent
))
nuc._fpy = parent
nuc.yield_data = FissionYieldDistribution.from_xml_element(fpy_elem)

View file

@ -118,6 +118,24 @@ def test_fpy_parent():
assert fpy_elem.get('parent') == 'U235'
assert len(fpy_elem) == 0
data = """
<depletion_chain>
<nuclide name="U235" reactions="1">
<reaction type="fission" Q="193405400.0"/>
</nuclide>
<nuclide name="U238" reactions="1">
<reaction type="fission" Q="200.0e6"/>
<neutron_fission_yields parent="U235"/>
</nuclide>
</depletion_chain>
"""
# U235 yields are missing, so we should get an exception
root = ET.fromstring(data)
elems = root.findall('nuclide')
with pytest.raises(ValueError, match="yields"):
u238 = nuclide.Nuclide.from_xml(elems[1], root)
def test_to_xml_element():
"""Test writing nuclide data to an XML element."""