diff --git a/armi/bookkeeping/db/database3.py b/armi/bookkeeping/db/database3.py index 12e8c18d5..6cc4b2d59 100644 --- a/armi/bookkeeping/db/database3.py +++ b/armi/bookkeeping/db/database3.py @@ -1307,8 +1307,7 @@ def _writeParams(self, h5group, comps): # flatten, store the data offsets and array shapes, and None locations # as attrs # - If not jagged, all top-level ndarrays are the same shape, so it is - # probably easier to replace Nones with ndarrays filled with special - # values. + # easier to replace Nones with ndarrays filled with special values. if parameters.NoDefault in data: data = None else: diff --git a/armi/bookkeeping/db/tests/test_database3.py b/armi/bookkeeping/db/tests/test_database3.py index 8f13152b0..bd3ebac59 100644 --- a/armi/bookkeeping/db/tests/test_database3.py +++ b/armi/bookkeeping/db/tests/test_database3.py @@ -14,14 +14,16 @@ r""" Tests for the Database3 class """ +# pylint: disable=missing-function-docstring,missing-class-docstring,abstract-method,protected-access,no-member,disallowed-name,invalid-name import subprocess import unittest import h5py import numpy -from armi.bookkeeping.db import database3 +from armi.bookkeeping.db import _getH5File, database3 from armi.reactor import grids +from armi.reactor import parameters from armi.reactor.tests import test_reactors from armi.tests import TEST_ROOT from armi.utils import getPreviousTimeNode @@ -50,6 +52,45 @@ def tearDown(self): self.stateRetainer.__exit__() self.td.__exit__(None, None, None) + def test_writeToDB(self): + self.r.p.cycle = 0 + self.r.p.timeNode = 0 + self.r.p.cycleLength = 0 + + # Adding some nonsense in, to test NoDefault params + self.r.p.availabilityFactor = parameters.NoDefault + + # validate that the H5 file gets bigger after the write + self.assertEqual(list(self.db.h5db.keys()), ["inputs"]) + self.db.writeToDB(self.r) + self.assertEqual(sorted(self.db.h5db.keys()), ["c00n00", "inputs"]) + + keys = [ + "Circle", + "Core", + "DerivedShape", + "Helix", + "HexAssembly", + "HexBlock", + "Hexagon", + "Reactor", + "layout", + ] + self.assertEqual(sorted(self.db.h5db["c00n00"].keys()), sorted(keys)) + + # validate availabilityFactor did not make it into the H5 file + rKeys = ["cycle", "cycleLength", "flags", "serialNum", "timeNode"] + self.assertEqual( + sorted(self.db.h5db["c00n00"]["Reactor"].keys()), sorted(rKeys) + ) + + def test_getH5File(self): + with self.assertRaises(TypeError): + _getH5File(None) + + h5 = _getH5File(self.db) + self.assertEqual(type(h5), h5py.File) + def makeHistory(self): """Walk the reactor through a few time steps and write them to the db.""" for cycle, node in ((cycle, node) for cycle in range(3) for node in range(3)): diff --git a/armi/utils/tests/test_plotting.py b/armi/utils/tests/test_plotting.py index d8e4bede7..4c647c2a7 100644 --- a/armi/utils/tests/test_plotting.py +++ b/armi/utils/tests/test_plotting.py @@ -35,38 +35,40 @@ class TestPlotting(unittest.TestCase): demonstrate how they are meant to be called. """ - # Change to False when you want to inspect the plots. Change back please. - removeFiles = True - @classmethod def setUpClass(cls): cls.o, cls.r = test_reactors.loadTestReactor() def test_plotDepthMap(self): # indirectly tests plot face map - # set some params to visualize - for i, b in enumerate(self.o.r.core.getBlocks()): - b.p.percentBu = i / 100 - fName = plotting.plotBlockDepthMap( - self.r.core, param="percentBu", fName="depthMapPlot.png", depthIndex=2 - ) - self._checkExists(fName) + with TemporaryDirectoryChanger(): + # set some params to visualize + for i, b in enumerate(self.o.r.core.getBlocks()): + b.p.percentBu = i / 100 + fName = plotting.plotBlockDepthMap( + self.r.core, param="percentBu", fName="depthMapPlot.png", depthIndex=2 + ) + self._checkExists(fName) def test_plotAssemblyTypes(self): - plotPath = "coreAssemblyTypes1.png" - plotting.plotAssemblyTypes(self.r.core.parent.blueprints, plotPath) - self._checkExists(plotPath) - - plotPath = "coreAssemblyTypes2.png" - plotting.plotAssemblyTypes( - self.r.core.parent.blueprints, plotPath, yAxisLabel="y axis", title="title" - ) - self._checkExists(plotPath) + with TemporaryDirectoryChanger(): + plotPath = "coreAssemblyTypes1.png" + plotting.plotAssemblyTypes(self.r.core.parent.blueprints, plotPath) + self._checkExists(plotPath) + + plotPath = "coreAssemblyTypes2.png" + plotting.plotAssemblyTypes( + self.r.core.parent.blueprints, + plotPath, + yAxisLabel="y axis", + title="title", + ) + self._checkExists(plotPath) - with self.assertRaises(ValueError): - plotting.plotAssemblyTypes(None, plotPath, None) + with self.assertRaises(ValueError): + plotting.plotAssemblyTypes(None, plotPath, None) def test_plotBlockFlux(self): - try: + with TemporaryDirectoryChanger(): xslib = isotxs.readBinary(ISOAA_PATH) self.r.core.lib = xslib @@ -87,14 +89,6 @@ def test_plotBlockFlux(self): bList2=blockList, ) self.assertTrue(os.path.exists("bList2.png")) - # can't test adjoint at the moment, testBlock doesn't like to .getMgFlux(adjoint=True) - finally: - os.remove("flux.txt") # secondarily created during the call. - os.remove("flux.png") # created during the call. - os.remove("peak.txt") # csecondarily reated during the call. - os.remove("peak.png") # created during the call. - os.remove("bList2.txt") # secondarily created during the call. - os.remove("bList2.png") # created during the call. def test_plotHexBlock(self): with TemporaryDirectoryChanger(): @@ -123,8 +117,6 @@ def test_plotCartesianBlock(self): def _checkExists(self, fName): self.assertTrue(os.path.exists(fName)) - if self.removeFiles: - os.remove(fName) if __name__ == "__main__":