Skip to content

Commit

Permalink
Corrrectly ignoring BP sections in PassiveDBLoadPlugin (#2055)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science authored Jan 15, 2025
1 parent ee691ab commit 3431c44
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 23 deletions.
1 change: 1 addition & 0 deletions armi/bookkeeping/db/passiveDBLoadPlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
110 changes: 110 additions & 0 deletions armi/bookkeeping/db/tests/test_passiveDBLoadPlugin.py
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 0 additions & 23 deletions armi/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions doc/release/0.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ New Features
API Changes
-----------
#. Removing ``Database3`` from the API, use ``Database``. (`PR#2052 <https://github.com/terrapower/armi/pull/2052>`_)
#. TBD

Bug Fixes
---------
#. Fixing BP-section ignoring tool in ``PassiveDBLoadPlugin``. (`PR#2055 <https://github.com/terrapower/armi/pull/2055>`_)
#. TBD

Quality Work
Expand Down

0 comments on commit 3431c44

Please sign in to comment.