Skip to content

Commit

Permalink
Making the xsLibrary tests more threadsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Sep 17, 2024
1 parent 0b3c7c1 commit 555cbd1
Showing 1 changed file with 21 additions and 74 deletions.
95 changes: 21 additions & 74 deletions armi/nuclearDataIO/tests/test_xsLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def assert_contains_only(self, container, shouldBeThere, shouldNotBeThere):
self.assertEqual(set(), container & set(shouldNotBeThere))


class TestXSlibraryMerging(TempFileMixin):
class AbstractTestXSlibraryMerging(TempFileMixin):
"""
A shared class that defines tests that should be true for all IsotxsLibrary merging.
Expand All @@ -296,36 +296,14 @@ class TestXSlibraryMerging(TempFileMixin):
This is just a base class, so it isn't run directly.
"""

@classmethod
def setUpClass(cls):
cls.libAA = None
cls.libAB = None
cls.libCombined = None
cls.libLumped = None

@classmethod
def tearDownClass(cls):
cls.libAA = None
cls.libAB = None
cls.libCombined = None
cls.libLumped = None
del cls.libAA
del cls.libAB
del cls.libCombined
del cls.libLumped

def setUp(self):
TempFileMixin.setUp(self)
# load a library that is in the ARMI tree. This should
# be a small library with LFPs, Actinides, structure, and coolant
for attrName, path in [
("libAA", self.getLibAAPath),
("libAB", self.getLibABPath),
("libCombined", self.getLibAA_ABPath),
("libLumped", self.getLibLumpedPath),
]:
if getattr(self.__class__, attrName) is None:
setattr(self.__class__, attrName, self.getReadFunc()(path()))
self.libAA = self.getReadFunc()(self.getLibAAPath())
self.libAB = self.getReadFunc()(self.getLibABPath())
self.libCombined = self.getReadFunc()(self.getLibAA_ABPath())
self.libLumped = self.getReadFunc()(self.getLibLumpedPath())

def getErrorType(self):
raise NotImplementedError()
Expand Down Expand Up @@ -368,16 +346,16 @@ def test_cannotMergeXSLibxWithDifferentGroupStructure(self):
def test_mergeEmptyXSLibWithOtherEssentiallyClonesTheOther(self):
emptyXSLib = xsLibraries.IsotxsLibrary()
emptyXSLib.merge(self.libAA)
self.__class__.libAA = None
self.libAA = None
self.getWriteFunc()(emptyXSLib, self.testFileName)
self.assertTrue(filecmp.cmp(self.getLibAAPath(), self.testFileName))

def test_mergeTwoXSLibFiles(self):
emptyXSLib = xsLibraries.IsotxsLibrary()
emptyXSLib.merge(self.libAA)
self.__class__.libAA = None
self.libAA = None
emptyXSLib.merge(self.libAB)
self.__class__.libAB = None
self.libAB = None
self.assertEqual(
set(self.libCombined.nuclideLabels), set(emptyXSLib.nuclideLabels)
)
Expand All @@ -388,9 +366,9 @@ def test_mergeTwoXSLibFiles(self):
def test_canRemoveIsotopes(self):
emptyXSLib = xsLibraries.IsotxsLibrary()
emptyXSLib.merge(self.libAA)
self.__class__.libAA = None
self.libAA = None
emptyXSLib.merge(self.libAB)
self.__class__.libAB = None
self.libAB = None
for nucId in [
"ZR93_7",
"ZR95_7",
Expand All @@ -414,7 +392,7 @@ def test_canRemoveIsotopes(self):
self.assertTrue(filecmp.cmp(self.getLibLumpedPath(), self.testFileName))


class Pmatrx_merge_Tests(TestXSlibraryMerging):
class Pmatrx_merge_Tests(AbstractTestXSlibraryMerging):
def getErrorType(self):
return OSError

Expand Down Expand Up @@ -448,7 +426,7 @@ def test_cannotMergeXSLibsWithDifferentGammaGroupStructures(self):
dummyXsLib.merge(self.libCombined)


class Isotxs_merge_Tests(TestXSlibraryMerging):
class Isotxs_merge_Tests(AbstractTestXSlibraryMerging):
def getErrorType(self):
return OSError

Expand All @@ -471,7 +449,7 @@ def getLibLumpedPath(self):
return ISOTXS_LUMPED


class Gamiso_merge_Tests(TestXSlibraryMerging):
class Gamiso_merge_Tests(AbstractTestXSlibraryMerging):
def getErrorType(self):
return OSError

Expand All @@ -495,47 +473,16 @@ def getLibLumpedPath(self):


class Combined_merge_Tests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.isotxsAA = None
cls.isotxsAB = None
cls.gamisoAA = None
cls.gamisoAB = None
cls.pmatrxAA = None
cls.pmatrxAB = None
cls.libCombined = None

@classmethod
def tearDownClass(cls):
cls.isotxsAA = None
cls.isotxsAB = None
cls.gamisoAA = None
cls.gamisoAB = None
cls.pmatrxAA = None
cls.pmatrxAB = None
cls.libCombined = None
del cls.isotxsAA
del cls.isotxsAB
del cls.gamisoAA
del cls.gamisoAB
del cls.pmatrxAA
del cls.pmatrxAB
del cls.libCombined

def setUp(self):
# load a library that is in the ARMI tree. This should
# be a small library with LFPs, Actinides, structure, and coolant
for attrName, path, readFunc in [
("isotxsAA", ISOTXS_AA, isotxs.readBinary),
("gamisoAA", GAMISO_AA, gamiso.readBinary),
("pmatrxAA", PMATRX_AA, pmatrx.readBinary),
("isotxsAB", ISOTXS_AB, isotxs.readBinary),
("gamisoAB", GAMISO_AB, gamiso.readBinary),
("pmatrxAB", PMATRX_AB, pmatrx.readBinary),
("libCombined", ISOTXS_AA_AB, isotxs.readBinary),
]:
if getattr(self.__class__, attrName) is None:
setattr(self.__class__, attrName, readFunc(path))
self.isotxsAA = isotxs.readBinary(ISOTXS_AA)
self.gamisoAA = gamiso.readBinary(GAMISO_AA)
self.pmatrxAA = pmatrx.readBinary(PMATRX_AA)
self.isotxsAB = isotxs.readBinary(ISOTXS_AB)
self.gamisoAB = gamiso.readBinary(GAMISO_AB)
self.pmatrxAB = pmatrx.readBinary(PMATRX_AB)
self.libCombined = isotxs.readBinary(ISOTXS_AA_AB)

def test_mergeAllXSLibFiles(self):
lib = xsLibraries.IsotxsLibrary()
Expand All @@ -546,4 +493,4 @@ def test_mergeAllXSLibFiles(self):


# Remove the abstract class, so that it does not run (all tests would fail)
del TestXSlibraryMerging
del AbstractTestXSlibraryMerging

0 comments on commit 555cbd1

Please sign in to comment.