From 3669709061f6dc51591bdb46ee6dbf6170b500d7 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Wed, 25 Mar 2020 06:29:21 -0400 Subject: [PATCH] Apply suggestions from code review * Use set operations (|=) rather than in-place methods (update) * Remove second arguments to some asserts in Chain.reduce testing Co-Authored-By: Paul Romano --- openmc/deplete/chain.py | 8 ++++---- tests/unit_tests/test_deplete_chain.py | 26 ++++++++++++------------ tests/unit_tests/test_deplete_nuclide.py | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/openmc/deplete/chain.py b/openmc/deplete/chain.py index d820fe520b..fce5051b0b 100644 --- a/openmc/deplete/chain.py +++ b/openmc/deplete/chain.py @@ -906,7 +906,7 @@ class Chain(object): def _follow(self, isotopes, level): """Return all isotopes present up to depth level""" - found = set(isotopes) + found = isotopes.copy() remaining = set(self.nuclide_dict) if not found.issubset(remaining): raise IndexError( @@ -916,7 +916,7 @@ class Chain(object): if level == 0: return found - remaining.difference_update(found) + remaining -= found depth = 0 next_iso = set() @@ -952,8 +952,8 @@ class Chain(object): # Prepare for next dig depth += 1 - isotopes.update(next_iso) - remaining.difference_update(next_iso) + isotopes |= next_iso + remaining -= next_iso next_iso.clear() # Process isotope that would have started next depth diff --git a/tests/unit_tests/test_deplete_chain.py b/tests/unit_tests/test_deplete_chain.py index b7a1e6c0f2..ba3be4e37a 100644 --- a/tests/unit_tests/test_deplete_chain.py +++ b/tests/unit_tests/test_deplete_chain.py @@ -479,18 +479,18 @@ def test_reduce(gnd_simple_chain): assert u5_round0.n_decay_modes == ref_U5.n_decay_modes for newmode, refmode in zip(u5_round0.decay_modes, ref_U5.decay_modes): assert newmode.target is None - assert newmode.type == refmode.type, newmode - assert newmode.branching_ratio == refmode.branching_ratio, newmode + assert newmode.type == refmode.type + assert newmode.branching_ratio == refmode.branching_ratio assert u5_round0.n_reaction_paths == ref_U5.n_reaction_paths for newrxn, refrxn in zip(u5_round0.reactions, ref_U5.reactions): - assert newrxn.target is None, newrxn - assert newrxn.type == refrxn.type, newrxn - assert newrxn.Q == refrxn.Q, newrxn - assert newrxn.branching_ratio == refrxn.branching_ratio, newrxn + assert newrxn.target is None + assert newrxn.type == refrxn.type + assert newrxn.Q == refrxn.Q + assert newrxn.branching_ratio == refrxn.branching_ratio assert u5_round0.yield_data is not None - assert u5_round0.yield_data.products == ("I135", ) + assert u5_round0.yield_data.products == ("I135",) assert u5_round0.yield_data.yield_matrix == ( ref_U5_yields.yield_matrix[:, ref_U5_yields.products.index("I135")] ) @@ -499,15 +499,15 @@ def test_reduce(gnd_simple_chain): assert bareI5.n_decay_modes == ref_iodine.n_decay_modes for newmode, refmode in zip(bareI5.decay_modes, ref_iodine.decay_modes): assert newmode.target is None - assert newmode.type == refmode.type, newmode - assert newmode.branching_ratio == refmode.branching_ratio, newmode + assert newmode.type == refmode.type + assert newmode.branching_ratio == refmode.branching_ratio assert bareI5.n_reaction_paths == ref_iodine.n_reaction_paths for newrxn, refrxn in zip(bareI5.reactions, ref_iodine.reactions): - assert newrxn.target is None, newrxn - assert newrxn.type == refrxn.type, newrxn - assert newrxn.Q == refrxn.Q, newrxn - assert newrxn.branching_ratio == refrxn.branching_ratio, newrxn + assert newrxn.target is None + assert newrxn.type == refrxn.type + assert newrxn.Q == refrxn.Q + assert newrxn.branching_ratio == refrxn.branching_ratio follow_u5 = gnd_simple_chain.reduce(["U235"], 1) u5_round1 = follow_u5["U235"] diff --git a/tests/unit_tests/test_deplete_nuclide.py b/tests/unit_tests/test_deplete_nuclide.py index 92b004845a..126206cc70 100644 --- a/tests/unit_tests/test_deplete_nuclide.py +++ b/tests/unit_tests/test_deplete_nuclide.py @@ -181,9 +181,9 @@ def test_fission_yield_distribution(): with_extras = yield_dist.restrict_products( ["Xe135", "Sm149", "H1", "U235"]) - assert strict_restrict.products == ("Sm149", "Xe135", ) + assert strict_restrict.products == ("Sm149", "Xe135") assert strict_restrict.energies == yield_dist.energies - assert with_extras.products == ("Sm149", "Xe135", ) + assert with_extras.products == ("Sm149", "Xe135") assert with_extras.energies == yield_dist.energies for ene, new_yields in strict_restrict.items(): for product in strict_restrict.products: