From a7b6737069859ba0f1ec8ac578a842453eea3fea Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Mon, 8 Jul 2019 14:01:57 -0500 Subject: [PATCH] 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 --- openmc/deplete/chain.py | 2 -- tests/unit_tests/test_deplete_chain.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/openmc/deplete/chain.py b/openmc/deplete/chain.py index 0267977d2c..0a52b78d7f 100644 --- a/openmc/deplete/chain.py +++ b/openmc/deplete/chain.py @@ -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: diff --git a/tests/unit_tests/test_deplete_chain.py b/tests/unit_tests/test_deplete_chain.py index 2458af7c51..33b13b596d 100644 --- a/tests/unit_tests/test_deplete_chain.py +++ b/tests/unit_tests/test_deplete_chain.py @@ -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)