diff --git a/armi/bookkeeping/db/passiveDBLoadPlugin.py b/armi/bookkeeping/db/passiveDBLoadPlugin.py index 4dcb9ee30..e832d07b1 100644 --- a/armi/bookkeeping/db/passiveDBLoadPlugin.py +++ b/armi/bookkeeping/db/passiveDBLoadPlugin.py @@ -33,6 +33,7 @@ class PassThroughYamlize(yamlize.Object): @classmethod def from_yaml(cls, loader, node, round_trip_data=None): + node.value = [] return yamlize.Object.from_yaml.__func__( PassThroughYamlize, loader, node, round_trip_data ) diff --git a/armi/bookkeeping/db/tests/test_passiveDBLoadPlugin.py b/armi/bookkeeping/db/tests/test_passiveDBLoadPlugin.py new file mode 100644 index 000000000..d7803b2ee --- /dev/null +++ b/armi/bookkeeping/db/tests/test_passiveDBLoadPlugin.py @@ -0,0 +1,110 @@ +# Copyright 2025 TerraPower, LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Provides functionality for testing the PassiveDBLoadPlugin.""" +import unittest +from copy import deepcopy +from io import StringIO + +from ruamel.yaml.cyaml import CLoader +from ruamel.yaml.nodes import MappingNode, ScalarNode + +from armi import context, getApp +from armi.bookkeeping.db.passiveDBLoadPlugin import ( + PassiveDBLoadPlugin, + PassThroughYamlize, +) +from armi.reactor.blocks import Block + + +class TestPassiveDBLoadPlugin(unittest.TestCase): + def setUp(self): + """ + Manipulate the standard App. We can't just configure our own, since the + pytest environment bleeds between tests. + """ + self.app = getApp() + self._backupApp = deepcopy(self.app) + + def tearDown(self): + """Restore the App to its original state.""" + import armi + + armi._app = self._backupApp + context.APP_NAME = "armi" + + def test_passiveDBLoadPlugin(self): + plug = PassiveDBLoadPlugin() + + # default case + bpSections = plug.defineBlueprintsSections() + self.assertEqual(len(bpSections), 0) + params = plug.defineParameters() + self.assertEqual(len(params), 0) + + # non-empty cases + PassiveDBLoadPlugin.SKIP_BP_SECTIONS = ["hi", "mom"] + PassiveDBLoadPlugin.UNKNOWN_PARAMS = {Block: ["fake1", "fake2"]} + bpSections = plug.defineBlueprintsSections() + self.assertEqual(len(bpSections), 2) + self.assertTrue(type(bpSections[0]), tuple) + self.assertEqual(bpSections[0][0], "hi") + self.assertTrue(type(bpSections[1]), tuple) + self.assertEqual(bpSections[1][0], "mom") + params = plug.defineParameters() + self.assertEqual(len(params), 1) + self.assertIn(Block, params) + + +class TestPassThroughYamlize(unittest.TestCase): + def test_passThroughYamlizeExample1(self): + # create node from known BP-style YAML object + node = MappingNode( + "test_passThroughYamlizeExample1", + [ + ( + ScalarNode(tag="tag:yaml.org,2002:str", value="core-wide"), + MappingNode( + tag="tag:yaml.org,2002:map", + value=[ + ( + ScalarNode( + tag="tag:yaml.org,2002:str", + value="fuel axial expansion", + ), + ScalarNode(tag="tag:yaml.org,2002:bool", value="False"), + ), + ( + ScalarNode( + tag="tag:yaml.org,2002:str", + value="grid plate radial expansion", + ), + ScalarNode(tag="tag:yaml.org,2002:bool", value="True"), + ), + ], + ), + ) + ], + ) + + # test that node is non-zero and has the "core-wide" section + self.assertEqual(node.value[0][0].value, "core-wide") + + # pass the YAML string through the known YAML + pty = PassThroughYamlize() + loader = CLoader(StringIO("")) + _p = pty.from_yaml(loader, node) + + # prove the section has been cleared + self.assertEqual(len(node.value), 0) diff --git a/armi/tests/test_plugins.py b/armi/tests/test_plugins.py index 7852ce653..5069674ac 100644 --- a/armi/tests/test_plugins.py +++ b/armi/tests/test_plugins.py @@ -28,7 +28,6 @@ settings, utils, ) -from armi.bookkeeping.db.passiveDBLoadPlugin import PassiveDBLoadPlugin from armi.physics.neutronics import NeutronicsPlugin from armi.reactor.blocks import Block from armi.reactor.converters.axialExpansionChanger import AxialExpansionChanger @@ -131,28 +130,6 @@ def test_axialExpansionHook(self): # Registering a plugin that implements the hook means we get that plugin's axial expander self.assertIs(second, SillyAxialExpansionChanger) - def test_passiveDBLoadPlugin(self): - plug = PassiveDBLoadPlugin() - - # default case - bpSections = plug.defineBlueprintsSections() - self.assertEqual(len(bpSections), 0) - params = plug.defineParameters() - self.assertEqual(len(params), 0) - - # non-empty cases - PassiveDBLoadPlugin.SKIP_BP_SECTIONS = ["hi", "mom"] - PassiveDBLoadPlugin.UNKNOWN_PARAMS = {Block: ["fake1", "fake2"]} - bpSections = plug.defineBlueprintsSections() - self.assertEqual(len(bpSections), 2) - self.assertTrue(type(bpSections[0]), tuple) - self.assertEqual(bpSections[0][0], "hi") - self.assertTrue(type(bpSections[1]), tuple) - self.assertEqual(bpSections[1][0], "mom") - params = plug.defineParameters() - self.assertEqual(len(params), 1) - self.assertIn(Block, params) - def test_beforeReactorConstructionHook(self): """Test that plugin hook successfully injects code before reactor initialization. diff --git a/doc/release/0.5.rst b/doc/release/0.5.rst index 1bcecd44d..a4dd48fbe 100644 --- a/doc/release/0.5.rst +++ b/doc/release/0.5.rst @@ -15,10 +15,12 @@ New Features API Changes ----------- #. Removing ``Database3`` from the API, use ``Database``. (`PR#2052 `_) +#. TBD Bug Fixes --------- #. Fixing check for jagged arrays during ``_writeParams``. (`PR#2051 `_) +#. Fixing BP-section ignoring tool in ``PassiveDBLoadPlugin``. (`PR#2055 `_) #. TBD Quality Work