Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using mockRunLogs in a better way #1106

Merged
merged 4 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion armi/bookkeeping/db/tests/test_comparedb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_diffSpecialData(self):
with mockRunLogs.BufferLog() as mock:
_diffSpecialData(refData, srcData3, out, dr)
self.assertEqual(dr.nDiffs(), 0)
self.assertIn("Special formatting parameters for", mock._outputStream)
self.assertIn("Special formatting parameters for", mock.getStdout())

# make an H5 datasets that will cause unpackSpecialData to fail
f4 = h5py.File("test_diffSpecialData4.hdf5", "w")
Expand Down
12 changes: 6 additions & 6 deletions armi/bookkeeping/report/tests/test_newReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ def test_reportLogs(self):
env = data.Report("Environment", "ARMI Env Info")

with mockRunLogs.BufferLog() as mock:
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
_ = env["badStuff"]
self.assertIn("Cannot locate group", mock._outputStream)
self.assertIn("Cannot locate group", mock.getStdout())

mock._outputStream = ""
self.assertEqual("", mock._outputStream)
mock.emptyStdout()
self.assertEqual("", mock.getStdout())
env.writeHTML()
self.assertIn("Writing HTML document", mock._outputStream)
self.assertIn("[info] HTML document", mock._outputStream)
self.assertIn("Writing HTML document", mock.getStdout())
self.assertIn("[info] HTML document", mock.getStdout())


if __name__ == "__main__":
Expand Down
78 changes: 39 additions & 39 deletions armi/bookkeeping/report/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,58 +78,58 @@ def test_reactorSpecificReporting(self):

with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
runLog.LOG.startLog("test_reactorSpecificReporting")
runLog.LOG.setVerbosity(logging.INFO)

writeAssemblyMassSummary(r)
self.assertIn("BOL Assembly Mass Summary", mock._outputStream)
self.assertIn("igniter fuel", mock._outputStream)
self.assertIn("primary control", mock._outputStream)
self.assertIn("plenum", mock._outputStream)
mock._outputStream = ""
self.assertIn("BOL Assembly Mass Summary", mock.getStdout())
self.assertIn("igniter fuel", mock.getStdout())
self.assertIn("primary control", mock.getStdout())
self.assertIn("plenum", mock.getStdout())
mock.emptyStdout()

setNeutronBalancesReport(r.core)
self.assertIn("No rate information", mock._outputStream)
mock._outputStream = ""
self.assertIn("No rate information", mock.getStdout())
mock.emptyStdout()

r.core.getFirstBlock().p.rateCap = 1.0
r.core.getFirstBlock().p.rateProdFis = 1.02
r.core.getFirstBlock().p.rateFis = 1.01
r.core.getFirstBlock().p.rateAbs = 1.0
setNeutronBalancesReport(r.core)
self.assertIn("Fission", mock._outputStream)
self.assertIn("Capture", mock._outputStream)
self.assertIn("Absorption", mock._outputStream)
self.assertIn("Leakage", mock._outputStream)
mock._outputStream = ""
self.assertIn("Fission", mock.getStdout())
self.assertIn("Capture", mock.getStdout())
self.assertIn("Absorption", mock.getStdout())
self.assertIn("Leakage", mock.getStdout())
mock.emptyStdout()

summarizePinDesign(r.core)
self.assertIn("Assembly Design Summary", mock._outputStream)
self.assertIn("Design & component information", mock._outputStream)
self.assertIn("Multiplicity", mock._outputStream)
mock._outputStream = ""
self.assertIn("Assembly Design Summary", mock.getStdout())
self.assertIn("Design & component information", mock.getStdout())
self.assertIn("Multiplicity", mock.getStdout())
mock.emptyStdout()

summarizePower(r.core)
self.assertIn("Power in radial shield", mock._outputStream)
self.assertIn("Power in primary control", mock._outputStream)
self.assertIn("Power in feed fuel", mock._outputStream)
mock._outputStream = ""
self.assertIn("Power in radial shield", mock.getStdout())
self.assertIn("Power in primary control", mock.getStdout())
self.assertIn("Power in feed fuel", mock.getStdout())
mock.emptyStdout()

writeCycleSummary(r.core)
self.assertIn("Core Average", mock._outputStream)
self.assertIn("Outlet Temp", mock._outputStream)
self.assertIn("End of Cycle", mock._outputStream)
mock._outputStream = ""
self.assertIn("Core Average", mock.getStdout())
self.assertIn("Outlet Temp", mock.getStdout())
self.assertIn("End of Cycle", mock.getStdout())
mock.emptyStdout()

# this report won't do much for the test reactor - improve test reactor
makeBlockDesignReport(r)
self.assertEqual(len(mock._outputStream), 0)
mock._outputStream = ""
self.assertEqual(len(mock.getStdout()), 0)
mock.emptyStdout()

# this report won't do much for the test reactor - improve test reactor
summarizePowerPeaking(r.core)
self.assertEqual(len(mock._outputStream), 0)
self.assertEqual(len(mock.getStdout()), 0)


class TestReportInterface(unittest.TestCase):
Expand All @@ -156,20 +156,20 @@ def test_interactBOLReportInt(self):

with mockRunLogs.BufferLog() as mock:
repInt.interactBOL()
self.assertIn("Writing assem layout", mock._outputStream)
self.assertIn("BOL Assembly", mock._outputStream)
self.assertIn("wetMass", mock._outputStream)
self.assertIn("moveable plenum", mock._outputStream)
self.assertIn("Writing assem layout", mock.getStdout())
self.assertIn("BOL Assembly", mock.getStdout())
self.assertIn("wetMass", mock.getStdout())
self.assertIn("moveable plenum", mock.getStdout())

def test_interactEveryNode(self):
o, r = loadTestReactor()
repInt = reportInterface.ReportInterface(r, o.cs)

with mockRunLogs.BufferLog() as mock:
repInt.interactEveryNode(0, 0)
self.assertIn("Cycle 0", mock._outputStream)
self.assertIn("node 0", mock._outputStream)
self.assertIn("keff=", mock._outputStream)
self.assertIn("Cycle 0", mock.getStdout())
self.assertIn("node 0", mock.getStdout())
self.assertIn("keff=", mock.getStdout())

def test_interactBOC(self):
o, r = loadTestReactor()
Expand All @@ -185,17 +185,17 @@ def test_interactEOC(self):

with mockRunLogs.BufferLog() as mock:
repInt.interactEOC(0)
self.assertIn("Cycle 0", mock._outputStream)
self.assertIn("TIMER REPORTS", mock._outputStream)
self.assertIn("Cycle 0", mock.getStdout())
self.assertIn("TIMER REPORTS", mock.getStdout())

def test_interactEOL(self):
o, r = loadTestReactor()
repInt = reportInterface.ReportInterface(r, o.cs)

with mockRunLogs.BufferLog() as mock:
repInt.interactEOL()
self.assertIn("Comprehensive Core Report", mock._outputStream)
self.assertIn("Assembly Area Fractions", mock._outputStream)
self.assertIn("Comprehensive Core Report", mock.getStdout())
self.assertIn("Assembly Area Fractions", mock.getStdout())


if __name__ == "__main__":
Expand Down
34 changes: 17 additions & 17 deletions armi/bookkeeping/tests/test_memoryProfiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def tearDown(self):
def test_fullBreakdown(self):
with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
runLog.LOG.startLog("test_fullBreakdown")
runLog.LOG.setVerbosity(logging.INFO)

Expand All @@ -45,13 +45,13 @@ def test_fullBreakdown(self):
self.memPro._printFullMemoryBreakdown(reportSize=False)

# do some basic testing
self.assertTrue(mock._outputStream.count("UNIQUE_INSTANCE_COUNT") > 10)
self.assertIn("garbage", mock._outputStream)
self.assertTrue(mock.getStdout().count("UNIQUE_INSTANCE_COUNT") > 10)
self.assertIn("garbage", mock.getStdout())

def test_displayMemoryUsage(self):
with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
runLog.LOG.startLog("test_displayMemUsage")
runLog.LOG.setVerbosity(logging.INFO)

Expand All @@ -60,12 +60,12 @@ def test_displayMemoryUsage(self):
self.memPro.displayMemoryUsage(1)

# do some basic testing
self.assertIn("End Memory Usage Report", mock._outputStream)
self.assertIn("End Memory Usage Report", mock.getStdout())

def test_printFullMemoryBreakdown(self):
with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
runLog.LOG.startLog("test_displayMemUsage")
runLog.LOG.setVerbosity(logging.INFO)

Expand All @@ -74,20 +74,20 @@ def test_printFullMemoryBreakdown(self):
self.memPro._printFullMemoryBreakdown(reportSize=True)

# do some basic testing
self.assertIn("UNIQUE_INSTANCE_COUNT", mock._outputStream)
self.assertIn(" MB", mock._outputStream)
self.assertIn("UNIQUE_INSTANCE_COUNT", mock.getStdout())
self.assertIn(" MB", mock.getStdout())

def test_getReferrers(self):
with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
testName = "test_getReferrers"
runLog.LOG.startLog(testName)
runLog.LOG.setVerbosity(logging.DEBUG)

# grab the referrers
self.memPro.getReferrers(self.r)
memLog = mock._outputStream
memLog = mock.getStdout()

# test the results
self.assertGreater(memLog.count("ref for"), 10)
Expand All @@ -99,7 +99,7 @@ def test_getReferrers(self):
def test_checkForDuplicateObjectsOnArmiModel(self):
with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
testName = "test_checkForDuplicateObjectsOnArmiModel"
runLog.LOG.startLog(testName)
runLog.LOG.setVerbosity(logging.IMPORTANT)
Expand All @@ -110,13 +110,13 @@ def test_checkForDuplicateObjectsOnArmiModel(self):

# validate the outputs are as we expect
self.assertIn(
"There are 2 unique objects stored as `.cs`", mock._outputStream
"There are 2 unique objects stored as `.cs`", mock.getStdout()
)
self.assertIn("Expected id", mock._outputStream)
self.assertIn("Expected object", mock._outputStream)
self.assertIn("These types of objects", mock._outputStream)
self.assertIn("MemoryProfiler", mock._outputStream)
self.assertIn("MainInterface", mock._outputStream)
self.assertIn("Expected id", mock.getStdout())
self.assertIn("Expected object", mock.getStdout())
self.assertIn("These types of objects", mock.getStdout())
self.assertIn("MemoryProfiler", mock.getStdout())
self.assertIn("MainInterface", mock.getStdout())

def test_profileMemoryUsageAction(self):
pmua = memoryProfiler.ProfileMemoryUsageAction("timeDesc")
Expand Down
8 changes: 4 additions & 4 deletions armi/cases/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ def test_run(self):

with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
runLog.LOG.startLog("test_run")
runLog.LOG.setVerbosity(logging.INFO)

case.run()

self.assertIn("Triggering BOL Event", mock._outputStream)
self.assertIn("xsGroups", mock._outputStream)
self.assertIn("Completed EveryNode - cycle 0", mock._outputStream)
self.assertIn("Triggering BOL Event", mock.getStdout())
self.assertIn("xsGroups", mock.getStdout())
self.assertIn("Completed EveryNode - cycle 0", mock.getStdout())

def test_clone(self):
testTitle = "CLONE_TEST"
Expand Down
12 changes: 6 additions & 6 deletions armi/cli/tests/test_runEntryPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def test_checkInputEntryPointInvoke(self):
ci.parse_args([ARMI_RUN_PATH])

with mockRunLogs.BufferLog() as mock:
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())

ci.invoke()

self.assertIn(ARMI_RUN_PATH, mock._outputStream)
self.assertIn("input is self consistent", mock._outputStream)
self.assertIn(ARMI_RUN_PATH, mock.getStdout())
self.assertIn("input is self consistent", mock.getStdout())


class TestCloneArmiRunCommandBatch(unittest.TestCase):
Expand Down Expand Up @@ -195,7 +195,7 @@ def test_convertDbBasics(self):
cdb.args.nodes = [1, 2, 3]
with self.assertRaises(ValueError):
cdb.invoke()
self.assertIn("Converting the", mock._outputStream)
self.assertIn("Converting the", mock.getStdout())

def test_convertDbOutputVersion(self):
cdb = ConvertDB()
Expand All @@ -221,9 +221,9 @@ def test_expandBlueprintsBasics(self):

# Since the file is fake, invoke() should exit early.
with mockRunLogs.BufferLog() as mock:
self.assertEqual("", mock._outputStream)
self.assertEqual("", mock.getStdout())
ebp.invoke()
self.assertIn("does not exist", mock._outputStream)
self.assertIn("does not exist", mock.getStdout())


class TestExtractInputs(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions armi/nuclearDataIO/tests/test_xsLibraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def test_mergeFailsWithNonIsotxsFiles(self):
lib = xsLibraries.IsotxsLibrary()
with self.assertRaises(OSError):
xsLibraries.mergeXSLibrariesInWorkingDirectory(lib, "ISOTXS", "")
self.assertIn(dummyFileName, log.getStdoutValue())
self.assertIn(dummyFileName, log.getStdout())
finally:
os.remove(dummyFileName)

Expand All @@ -261,7 +261,7 @@ def test_mergeFailsWithNonIsotxsFiles(self):
xsLibraries.mergeXSLibrariesInWorkingDirectory(lib)
self.assertIn(
f"{dummyFileName} in the merging of ISOXX files",
log.getStdoutValue(),
log.getStdout(),
)
finally:
pass
Expand Down
10 changes: 5 additions & 5 deletions armi/nuclearDataIO/tests/test_xsNuclides.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,30 @@ def test_nuclide_modifyingNuclideAttributesUpdatesTheIsotxsNuclide(self):

def test_nuclide_newLabelsDontCauseWarnings(self):
with mockRunLogs.BufferLog() as logCapture:
self.assertEqual("", logCapture._outputStream)
self.assertEqual("", logCapture.getStdout())
fe = nuclideBases.byName["FE"]
feNuc = xsNuclides.XSNuclide(None, "FEAA")
feNuc.isotxsMetadata["nuclideId"] = fe.name
feNuc.updateBaseNuclide()
self.assertEqual(fe, feNuc._base)
self.assertEqual("", logCapture._outputStream)
self.assertEqual("", logCapture.getStdout())

def test_nuclide_oldLabelsCauseWarnings(self):
with mockRunLogs.BufferLog() as logCapture:
self.assertEqual("", logCapture._outputStream)
self.assertEqual("", logCapture.getStdout())
pu = nuclideBases.byName["PU239"]
puNuc = xsNuclides.XSNuclide(None, "PLUTAA")
puNuc.isotxsMetadata["nuclideId"] = pu.name
puNuc.updateBaseNuclide()
self.assertEqual(pu, puNuc._base)
length = len(logCapture._outputStream)
length = len(logCapture.getStdout())
self.assertGreater(length, 15)
# now get it with a legitmate same label, length shouldn't change
puNuc = xsNuclides.XSNuclide(None, "PLUTAB")
puNuc.isotxsMetadata["nuclideId"] = pu.name
puNuc.updateBaseNuclide()
self.assertEqual(pu, puNuc._base)
self.assertEqual(length, len(logCapture._outputStream))
self.assertEqual(length, len(logCapture.getStdout()))

def test_nuclide_nuclideBaseMethodsShouldNotFail(self):
for nuc in self.lib.nuclides:
Expand Down
4 changes: 2 additions & 2 deletions armi/reactor/converters/tests/test_axialExpansionChanger.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,8 @@ def test_specifyTargetComponet_BlueprintSpecified(self):
assembly.reestablishBlockOrder()
with mockRunLogs.BufferLog() as mock:
self.obj.performPrescribedAxialExpansion(assembly, [dummy], [0.01])
self.assertIn("(blueprints defined)", mock._outputStream)
self.assertIn("(inferred)", mock._outputStream)
self.assertIn("(blueprints defined)", mock.getStdout())
self.assertIn("(inferred)", mock.getStdout())


class TestInputHeightsConsideredHot(unittest.TestCase):
Expand Down
3 changes: 1 addition & 2 deletions armi/reactor/tests/test_reactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,11 @@ def test_getNuclideCategoriesLogging(self):

# run the actual method in question
self.r.core.getNuclideCategories()
messages = log.getStdoutValue()
messages = log.getStdout()

self.assertIn("Nuclide categorization", messages)
self.assertIn("Structure", messages)


if __name__ == "__main__":
# import sys;sys.argv = ["", "ReactorTests.test_genAssembliesAddedThisCycle"]
unittest.main()
Loading