Skip to content

Commit

Permalink
Adding tests and crumbs for settings
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Dec 5, 2023
1 parent 416cd2a commit 07d42c7
Showing 1 changed file with 54 additions and 9 deletions.
63 changes: 54 additions & 9 deletions armi/tests/test_runLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@

class TestRunLog(unittest.TestCase):
def test_setVerbosityFromInteger(self):
"""Test that the log verbosity can be set with an integer."""
"""Test that the log verbosity can be set with an integer.
.. test:: The run log verbosity can be configured with an integer.
:id: T_ARMI_LOG0
:tests: R_ARMI_LOG
"""
log = runLog._RunLog(1)
expectedStrVerbosity = "debug"
verbosityRank = log.getLogVerbosityRank(expectedStrVerbosity)
Expand All @@ -37,8 +42,8 @@ def test_setVerbosityFromString(self):
"""
Test that the log verbosity can be set with a string.
.. test:: The run log has configurable verbosity.
:id: T_ARMI_LOG0
.. test:: The run log verbosity can be configured with a string.
:id: T_ARMI_LOG1
:tests: R_ARMI_LOG
"""
log = runLog._RunLog(1)
Expand Down Expand Up @@ -105,7 +110,12 @@ def test_getWhiteSpace(self):
self.assertEqual(space1, space9)

def test_warningReport(self):
"""A simple test of the warning tracking and reporting logic."""
"""A simple test of the warning tracking and reporting logic.
.. test:: Generate a warning report after a simulation is complete.
:id: T_ARMI_LOG2
:tests: R_ARMI_LOG
"""
# create the logger and do some logging
log = runLog.LOG = runLog._RunLog(321)
log.startLog("test_warningReport")
Expand Down Expand Up @@ -147,7 +157,12 @@ def test_warningReport(self):
log.logger = backupLog

def test_warningReportInvalid(self):
"""A test of warningReport in an invalid situation."""
"""A test of warningReport in an invalid situation.
.. test:: Test an important edge case for a warning report.
:id: T_ARMI_LOG3
:tests: R_ARMI_LOG
"""
# create the logger and do some logging
testName = "test_warningReportInvalid"
log = runLog.LOG = runLog._RunLog(323)
Expand Down Expand Up @@ -216,7 +231,7 @@ def test_setVerbosity(self):
"""Let's test the setVerbosity() method carefully.
.. test:: The run log has configurable verbosity.
:id: T_ARMI_LOG1
:id: T_ARMI_LOG4
:tests: R_ARMI_LOG
.. test:: The run log can log to stream.
Expand Down Expand Up @@ -265,9 +280,15 @@ def test_setVerbosity(self):
self.assertEqual(runLog.LOG.getVerbosity(), logging.WARNING)

def test_setVerbosityBeforeStartLog(self):
"""The user/dev may accidentally call ``setVerbosity()`` before ``startLog()``, this should be mostly supportable."""
"""The user/dev may accidentally call ``setVerbosity()`` before ``startLog()``,
this should be mostly supportable. This is just an edge case.
.. test:: Test that we support the user setting log verbosity BEFORE the logging starts.
:id: T_ARMI_LOG5
:tests: R_ARMI_LOG
"""
with mockRunLogs.BufferLog() as mock:
# we should start with a clean slate
# we should start with a clean slate, before debug logging
self.assertEqual("", mock.getStdout())
runLog.LOG.setVerbosity(logging.DEBUG)
runLog.LOG.startLog("test_setVerbosityBeforeStartLog")
Expand All @@ -278,6 +299,19 @@ def test_setVerbosityBeforeStartLog(self):
self.assertIn("hi", mock.getStdout())
mock.emptyStdout()

# we should start with a clean slate, before info loggin
self.assertEqual("", mock.getStdout())
runLog.LOG.setVerbosity(logging.INFO)
runLog.LOG.startLog("test_setVerbosityBeforeStartLog2")

# we should start at info level, and that should be working correctly
self.assertEqual(runLog.LOG.getVerbosity(), logging.INFO)
runLog.debug("nope")
runLog.info("hi")
self.assertIn("hi", mock.getStdout())
self.assertNotIn("nope", mock.getStdout())
mock.emptyStdout()

def test_callingStartLogMultipleTimes(self):
"""Calling startLog() multiple times will lead to multiple output files, but logging should still work."""
with mockRunLogs.BufferLog() as mock:
Expand Down Expand Up @@ -377,7 +411,12 @@ def test_concatenateLogs(self):
self.assertFalse(os.path.exists(stderrFile))

def test_createLogDir(self):
"""Test the createLogDir() method."""
"""Test the createLogDir() method.
.. test:: Test that log directories can be created for logging output files.
:id: T_ARMI_LOG6
:tests: R_ARMI_LOG
"""
with TemporaryDirectoryChanger():
logDir = "test_createLogDir"
self.assertFalse(os.path.exists(logDir))
Expand Down Expand Up @@ -410,6 +449,12 @@ def test_allowStopDuplicates(self):
self.assertEqual(len(self.rl.filters), 1)

def test_write(self):
"""Test that we can write text to the logger output stream.
.. test:: Write logging text to the logging stream and/or file.
:id: T_ARMI_LOG7
:tests: R_ARMI_LOG
"""
# divert the logging to a stream, to make testing easier
stream = StringIO()
handler = logging.StreamHandler(stream)
Expand Down

0 comments on commit 07d42c7

Please sign in to comment.