def test_parentRunLogging(self): """A basic test of the logging of the parent runLog""" # init the _RunLog object log = runLog.LOG = runLog._RunLog(0) log.startLog("test_parentRunLogging") context.createLogDir(0) log.setVerbosity(logging.INFO) # divert the logging to a stream, to make testing easier stream = StringIO() handler = logging.StreamHandler(stream) log.logger.handlers = [handler] # log some things log.log("debug", "You shouldn't see this.", single=False, label=None) log.log("warning", "Hello, ", single=False, label=None) log.log("error", "world!", single=False, label=None) log.logger.flush() log.logger.close() runLog.close(99) # test what was logged streamVal = stream.getvalue() self.assertIn("Hello", streamVal, msg=streamVal) self.assertIn("world", streamVal, msg=streamVal)
def test_closeLogging(self): """A basic test of the close() functionality""" def validate_loggers(log): """little test helper, to make sure our loggers still look right""" handlers = [str(h) for h in log.logger.handlers] self.assertEqual(len(handlers), 1, msg=",".join(handlers)) stderrHandlers = [str(h) for h in log.stderrLogger.handlers] self.assertEqual(len(stderrHandlers), 1, msg=",".join(stderrHandlers)) # init logger log = runLog.LOG = runLog._RunLog(777) validate_loggers(log) # start the logging for real log.startLog("test_closeLogging") context.createLogDir(0) validate_loggers(log) # close() and test that we have correctly nullified our loggers runLog.close(1) validate_loggers(log) # in a real run, the parent process would close() after all the children runLog.close(0)
def test_concatenateLogs(self): """simple test of the concat logs function""" # create the log dir logDir = "test_concatenateLogs" if os.path.exists(logDir): rmtree(logDir) context.createLogDir(0, logDir) # create as stdout file stdoutFile = os.path.join(logDir, logDir + ".0.0.stdout") with open(stdoutFile, "w") as f: f.write("hello world\n") self.assertTrue(os.path.exists(stdoutFile)) # create a stderr file stderrFile = os.path.join(logDir, logDir + ".0.0.stderr") with open(stderrFile, "w") as f: f.write("goodbye cruel world\n") self.assertTrue(os.path.exists(stderrFile)) # concat logs runLog.concatenateLogs(logDir=logDir) # verify output self.assertFalse(os.path.exists(stdoutFile)) self.assertFalse(os.path.exists(stderrFile))
def test_warningReport(self): """A simple test of the warning tracking and reporting logic""" # create the logger and do some logging log = runLog.LOG = runLog._RunLog(321) log.startLog("test_warningReport") context.createLogDir(0) # divert the logging to a stream, to make testing easier stream = StringIO() handler = logging.StreamHandler(stream) log.logger.handlers = [handler] # log some things log.setVerbosity(logging.INFO) log.log("warning", "test_warningReport", single=True, label=None) log.log("debug", "invisible due to log level", single=False, label=None) log.log("warning", "test_warningReport", single=True, label=None) log.log("error", "high level something", single=False, label=None) # test that the logging found some duplicate outputs dupsFilter = log.getDuplicatesFilter() self.assertTrue(dupsFilter is not None) warnings = dupsFilter.singleWarningMessageCounts self.assertGreater(len(warnings), 0) # run the warning report log.warningReport() runLog.close(1) runLog.close(0) # test what was logged streamVal = stream.getvalue() self.assertIn("test_warningReport", streamVal, msg=streamVal) self.assertIn("Final Warning Count", streamVal, msg=streamVal) self.assertEqual(streamVal.count("test_warningReport"), 2, msg=streamVal)
def test_createLogDir(self): """Test the createLogDir() method""" logDir = TEST_DIR1 self.assertFalse(os.path.exists(logDir)) context.createLogDir(0, logDir) self.assertTrue(os.path.exists(logDir))