MCPcopy Index your code
hub / github.com/python/cpython / test_flush_on_close

Method test_flush_on_close

Lib/test/test_logging.py:1208–1236  ·  view source on GitHub ↗

Test that the flush-on-close configuration works as expected.

(self)

Source from the content-addressed store, hash-verified

1206 self.assert_log_lines(lines)
1207
1208 def test_flush_on_close(self):
1209 """
1210 Test that the flush-on-close configuration works as expected.
1211 """
1212 self.mem_logger.debug(self.next_message())
1213 self.assert_log_lines([])
1214 self.mem_logger.info(self.next_message())
1215 self.assert_log_lines([])
1216 self.mem_logger.removeHandler(self.mem_hdlr)
1217 # Default behaviour is to flush on close. Check that it happens.
1218 self.mem_hdlr.close()
1219 lines = [
1220 ('DEBUG', '1'),
1221 ('INFO', '2'),
1222 ]
1223 self.assert_log_lines(lines)
1224 # Now configure for flushing not to be done on close.
1225 self.mem_hdlr = logging.handlers.MemoryHandler(10, logging.WARNING,
1226 self.root_hdlr,
1227 False)
1228 self.mem_logger.addHandler(self.mem_hdlr)
1229 self.mem_logger.debug(self.next_message())
1230 self.assert_log_lines(lines) # no change
1231 self.mem_logger.info(self.next_message())
1232 self.assert_log_lines(lines) # no change
1233 self.mem_logger.removeHandler(self.mem_hdlr)
1234 self.mem_hdlr.close()
1235 # assert that no new lines have been added
1236 self.assert_log_lines(lines) # no change
1237
1238 def test_shutdown_flush_on_close(self):
1239 """

Callers

nothing calls this directly

Calls 7

next_messageMethod · 0.80
assert_log_linesMethod · 0.80
removeHandlerMethod · 0.80
addHandlerMethod · 0.80
debugMethod · 0.45
infoMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected