Test failure modes for Chain.set_capture_branches

Remove one validation check, that the passed item is a
dict of strings. The check is covered when every key is
inspected to ensure all parents exist in the chain
This commit is contained in:
Andrew Johnson 2019-07-08 14:01:57 -05:00
parent 5b7253bca0
commit a7b6737069
No known key found for this signature in database
GPG key ID: 253418E91B7F6FEB
2 changed files with 19 additions and 2 deletions

View file

@ -525,8 +525,6 @@ class Chain(object):
# Check for validity before manipulation
check_type("branch_ratios", branch_ratios, dict, str)
for parent, sub in branch_ratios.items():
if parent not in self:
if strict:

View file

@ -310,3 +310,22 @@ def test_capture_branch_no_rxn():
phrase = "U234 does not have capture reactions"
with pytest.raises(AttributeError, match=phrase):
chain.set_capture_branches(u4br)
def test_capture_branch_failures(simple_chain):
"""Test failure modes for setting capture branch ratios"""
# Parent isotope not present
br = {"X": {"A": 0.6, "B": 0.7}}
with pytest.raises(KeyError, match="X"):
simple_chain.set_capture_branches(br)
# Product isotope not present
br = {"C": {"X": 0.4, "A": 0.2, "B": 0.4}}
with pytest.raises(KeyError, match="X"):
simple_chain.set_capture_branches(br)
# Sum of ratios > 1.0
br = {"C": {"A": 1.0, "B": 1.0}}
with pytest.raises(ValueError, match="C ratios"):
simple_chain.set_capture_branches(br)