summaryrefslogtreecommitdiff
path: root/Lib/test/test_logging.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2013-04-12 17:04:23 +0100
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2013-04-12 17:04:23 +0100
commita713079ed82b0bfd841562fd7ac043313feb8ef6 (patch)
treec7f74851f926b28cd435845184aa5628b3ad84d8 /Lib/test/test_logging.py
parent8a9e38e71519066ec256ac685c7bcb33ab429800 (diff)
downloadcpython-git-a713079ed82b0bfd841562fd7ac043313feb8ef6.tar.gz
Closed #9556: Allowed specifying a time-of-day for a TimedRotatingFileHandler to rotate.
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r--Lib/test/test_logging.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index fea2b00fe3..73adae5b08 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3949,6 +3949,48 @@ class TimedRotatingFileHandlerTest(BaseFileTest):
assertRaises(ValueError, logging.handlers.TimedRotatingFileHandler,
self.fn, 'W7', delay=True)
+ def test_compute_rollover_daily_attime(self):
+ currentTime = 0
+ atTime = datetime.time(12, 0, 0)
+ rh = logging.handlers.TimedRotatingFileHandler(
+ self.fn, when='MIDNIGHT', interval=1, backupCount=0, utc=True,
+ atTime=atTime)
+
+ actual = rh.computeRollover(currentTime)
+ self.assertEqual(actual, currentTime + 12 * 60 * 60)
+
+ actual = rh.computeRollover(currentTime + 13 * 60 * 60)
+ self.assertEqual(actual, currentTime + 36 * 60 * 60)
+
+ rh.close()
+
+ def test_compute_rollover_weekly_attime(self):
+ currentTime = 0
+ atTime = datetime.time(12, 0, 0)
+
+ wday = datetime.datetime.fromtimestamp(currentTime).weekday()
+ for day in range(7):
+ rh = logging.handlers.TimedRotatingFileHandler(
+ self.fn, when='W%d' % day, interval=1, backupCount=0, utc=True,
+ atTime=atTime)
+
+ if wday > day:
+ expected = (7 - wday + day)
+ else:
+ expected = (day - wday)
+ expected *= 24 * 60 * 60
+ expected += 12 * 60 * 60
+ actual = rh.computeRollover(currentTime)
+ self.assertEqual(actual, expected)
+ if day == wday:
+ # goes into following week
+ expected += 7 * 24 * 60 * 60
+ actual = rh.computeRollover(currentTime + 13 * 60 * 60)
+ self.assertEqual(actual, expected)
+
+ rh.close()
+
+
def secs(**kw):
return datetime.timedelta(**kw) // datetime.timedelta(seconds=1)