Skip to content

Commit 07d42c7

Browse files
committed
Adding tests and crumbs for settings
1 parent 416cd2a commit 07d42c7

File tree

1 file changed

+54
-9
lines changed

1 file changed

+54
-9
lines changed

armi/tests/test_runLog.py

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525

2626
class TestRunLog(unittest.TestCase):
2727
def test_setVerbosityFromInteger(self):
28-
"""Test that the log verbosity can be set with an integer."""
28+
"""Test that the log verbosity can be set with an integer.
29+
30+
.. test:: The run log verbosity can be configured with an integer.
31+
:id: T_ARMI_LOG0
32+
:tests: R_ARMI_LOG
33+
"""
2934
log = runLog._RunLog(1)
3035
expectedStrVerbosity = "debug"
3136
verbosityRank = log.getLogVerbosityRank(expectedStrVerbosity)
@@ -37,8 +42,8 @@ def test_setVerbosityFromString(self):
3742
"""
3843
Test that the log verbosity can be set with a string.
3944
40-
.. test:: The run log has configurable verbosity.
41-
:id: T_ARMI_LOG0
45+
.. test:: The run log verbosity can be configured with a string.
46+
:id: T_ARMI_LOG1
4247
:tests: R_ARMI_LOG
4348
"""
4449
log = runLog._RunLog(1)
@@ -105,7 +110,12 @@ def test_getWhiteSpace(self):
105110
self.assertEqual(space1, space9)
106111

107112
def test_warningReport(self):
108-
"""A simple test of the warning tracking and reporting logic."""
113+
"""A simple test of the warning tracking and reporting logic.
114+
115+
.. test:: Generate a warning report after a simulation is complete.
116+
:id: T_ARMI_LOG2
117+
:tests: R_ARMI_LOG
118+
"""
109119
# create the logger and do some logging
110120
log = runLog.LOG = runLog._RunLog(321)
111121
log.startLog("test_warningReport")
@@ -147,7 +157,12 @@ def test_warningReport(self):
147157
log.logger = backupLog
148158

149159
def test_warningReportInvalid(self):
150-
"""A test of warningReport in an invalid situation."""
160+
"""A test of warningReport in an invalid situation.
161+
162+
.. test:: Test an important edge case for a warning report.
163+
:id: T_ARMI_LOG3
164+
:tests: R_ARMI_LOG
165+
"""
151166
# create the logger and do some logging
152167
testName = "test_warningReportInvalid"
153168
log = runLog.LOG = runLog._RunLog(323)
@@ -216,7 +231,7 @@ def test_setVerbosity(self):
216231
"""Let's test the setVerbosity() method carefully.
217232
218233
.. test:: The run log has configurable verbosity.
219-
:id: T_ARMI_LOG1
234+
:id: T_ARMI_LOG4
220235
:tests: R_ARMI_LOG
221236
222237
.. test:: The run log can log to stream.
@@ -265,9 +280,15 @@ def test_setVerbosity(self):
265280
self.assertEqual(runLog.LOG.getVerbosity(), logging.WARNING)
266281

267282
def test_setVerbosityBeforeStartLog(self):
268-
"""The user/dev may accidentally call ``setVerbosity()`` before ``startLog()``, this should be mostly supportable."""
283+
"""The user/dev may accidentally call ``setVerbosity()`` before ``startLog()``,
284+
this should be mostly supportable. This is just an edge case.
285+
286+
.. test:: Test that we support the user setting log verbosity BEFORE the logging starts.
287+
:id: T_ARMI_LOG5
288+
:tests: R_ARMI_LOG
289+
"""
269290
with mockRunLogs.BufferLog() as mock:
270-
# we should start with a clean slate
291+
# we should start with a clean slate, before debug logging
271292
self.assertEqual("", mock.getStdout())
272293
runLog.LOG.setVerbosity(logging.DEBUG)
273294
runLog.LOG.startLog("test_setVerbosityBeforeStartLog")
@@ -278,6 +299,19 @@ def test_setVerbosityBeforeStartLog(self):
278299
self.assertIn("hi", mock.getStdout())
279300
mock.emptyStdout()
280301

302+
# we should start with a clean slate, before info loggin
303+
self.assertEqual("", mock.getStdout())
304+
runLog.LOG.setVerbosity(logging.INFO)
305+
runLog.LOG.startLog("test_setVerbosityBeforeStartLog2")
306+
307+
# we should start at info level, and that should be working correctly
308+
self.assertEqual(runLog.LOG.getVerbosity(), logging.INFO)
309+
runLog.debug("nope")
310+
runLog.info("hi")
311+
self.assertIn("hi", mock.getStdout())
312+
self.assertNotIn("nope", mock.getStdout())
313+
mock.emptyStdout()
314+
281315
def test_callingStartLogMultipleTimes(self):
282316
"""Calling startLog() multiple times will lead to multiple output files, but logging should still work."""
283317
with mockRunLogs.BufferLog() as mock:
@@ -377,7 +411,12 @@ def test_concatenateLogs(self):
377411
self.assertFalse(os.path.exists(stderrFile))
378412

379413
def test_createLogDir(self):
380-
"""Test the createLogDir() method."""
414+
"""Test the createLogDir() method.
415+
416+
.. test:: Test that log directories can be created for logging output files.
417+
:id: T_ARMI_LOG6
418+
:tests: R_ARMI_LOG
419+
"""
381420
with TemporaryDirectoryChanger():
382421
logDir = "test_createLogDir"
383422
self.assertFalse(os.path.exists(logDir))
@@ -410,6 +449,12 @@ def test_allowStopDuplicates(self):
410449
self.assertEqual(len(self.rl.filters), 1)
411450

412451
def test_write(self):
452+
"""Test that we can write text to the logger output stream.
453+
454+
.. test:: Write logging text to the logging stream and/or file.
455+
:id: T_ARMI_LOG7
456+
:tests: R_ARMI_LOG
457+
"""
413458
# divert the logging to a stream, to make testing easier
414459
stream = StringIO()
415460
handler = logging.StreamHandler(stream)

0 commit comments

Comments
 (0)