From 33581203c85520da531430b89068c9d3926ccaca Mon Sep 17 00:00:00 2001 From: Dennis Lee Date: Tue, 9 Apr 2024 15:52:44 -0500 Subject: [PATCH] Added test for WMCore.WMLogging.MyTimedRotatingFileHandler --- test/python/WMCore_t/WMLogging_t.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/test/python/WMCore_t/WMLogging_t.py b/test/python/WMCore_t/WMLogging_t.py index bd40f31ee6a..a536becd1ac 100644 --- a/test/python/WMCore_t/WMLogging_t.py +++ b/test/python/WMCore_t/WMLogging_t.py @@ -1,10 +1,12 @@ #!/usr/bin/env python # encoding: utf-8 from builtins import range +from datetime import date import logging import unittest import os -from WMCore.WMLogging import CouchHandler + +from WMCore.WMLogging import CouchHandler, MyTimedRotatingFileHandler from WMCore.Database.CMSCouch import CouchServer class WMLoggingTest(unittest.TestCase): @@ -25,6 +27,19 @@ def tearDown(self): # This used to test self._exc_info to only run on success. Broke in 2.7. Removed. self.server.deleteDatabase(self.dbname) + def testRotatingLogHandler(self): + """ + Test to make sure a date is in or will be added to the logName + """ + todayStr = date.today().strftime("%Y%m%d") + logName = "mylog.log" + handler = MyTimedRotatingFileHandler(logName, 'midnight', backupCount = 10) + self.assertIn(todayStr, handler.baseFilename) + + logName = f"mylog-{todayStr}.log" + handler = MyTimedRotatingFileHandler(logName, 'midnight', backupCount = 10) + self.assertIn(todayStr, handler.baseFilename) + def testLog(self): """ Write ten log messages to the database at three different levels