25
25
26
26
class TestRunLog (unittest .TestCase ):
27
27
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
+ """
29
34
log = runLog ._RunLog (1 )
30
35
expectedStrVerbosity = "debug"
31
36
verbosityRank = log .getLogVerbosityRank (expectedStrVerbosity )
@@ -37,8 +42,8 @@ def test_setVerbosityFromString(self):
37
42
"""
38
43
Test that the log verbosity can be set with a string.
39
44
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
42
47
:tests: R_ARMI_LOG
43
48
"""
44
49
log = runLog ._RunLog (1 )
@@ -105,7 +110,12 @@ def test_getWhiteSpace(self):
105
110
self .assertEqual (space1 , space9 )
106
111
107
112
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
+ """
109
119
# create the logger and do some logging
110
120
log = runLog .LOG = runLog ._RunLog (321 )
111
121
log .startLog ("test_warningReport" )
@@ -147,7 +157,12 @@ def test_warningReport(self):
147
157
log .logger = backupLog
148
158
149
159
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
+ """
151
166
# create the logger and do some logging
152
167
testName = "test_warningReportInvalid"
153
168
log = runLog .LOG = runLog ._RunLog (323 )
@@ -216,7 +231,7 @@ def test_setVerbosity(self):
216
231
"""Let's test the setVerbosity() method carefully.
217
232
218
233
.. test:: The run log has configurable verbosity.
219
- :id: T_ARMI_LOG1
234
+ :id: T_ARMI_LOG4
220
235
:tests: R_ARMI_LOG
221
236
222
237
.. test:: The run log can log to stream.
@@ -265,9 +280,15 @@ def test_setVerbosity(self):
265
280
self .assertEqual (runLog .LOG .getVerbosity (), logging .WARNING )
266
281
267
282
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
+ """
269
290
with mockRunLogs .BufferLog () as mock :
270
- # we should start with a clean slate
291
+ # we should start with a clean slate, before debug logging
271
292
self .assertEqual ("" , mock .getStdout ())
272
293
runLog .LOG .setVerbosity (logging .DEBUG )
273
294
runLog .LOG .startLog ("test_setVerbosityBeforeStartLog" )
@@ -278,6 +299,19 @@ def test_setVerbosityBeforeStartLog(self):
278
299
self .assertIn ("hi" , mock .getStdout ())
279
300
mock .emptyStdout ()
280
301
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
+
281
315
def test_callingStartLogMultipleTimes (self ):
282
316
"""Calling startLog() multiple times will lead to multiple output files, but logging should still work."""
283
317
with mockRunLogs .BufferLog () as mock :
@@ -377,7 +411,12 @@ def test_concatenateLogs(self):
377
411
self .assertFalse (os .path .exists (stderrFile ))
378
412
379
413
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
+ """
381
420
with TemporaryDirectoryChanger ():
382
421
logDir = "test_createLogDir"
383
422
self .assertFalse (os .path .exists (logDir ))
@@ -410,6 +449,12 @@ def test_allowStopDuplicates(self):
410
449
self .assertEqual (len (self .rl .filters ), 1 )
411
450
412
451
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
+ """
413
458
# divert the logging to a stream, to make testing easier
414
459
stream = StringIO ()
415
460
handler = logging .StreamHandler (stream )
0 commit comments