From 07d42c749bf4a8804cd83eba244e9e8da7192d06 Mon Sep 17 00:00:00 2001 From: jstilley Date: Tue, 5 Dec 2023 09:58:17 -0800 Subject: [PATCH] Adding tests and crumbs for settings --- armi/tests/test_runLog.py | 63 +++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/armi/tests/test_runLog.py b/armi/tests/test_runLog.py index 822ffd015..c79bfd139 100644 --- a/armi/tests/test_runLog.py +++ b/armi/tests/test_runLog.py @@ -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) @@ -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) @@ -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") @@ -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) @@ -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. @@ -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") @@ -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: @@ -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)) @@ -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)