Kaydet (Commit) 89c8862e authored tarafından Vinay Sajip's avatar Vinay Sajip

Close handler opened in test.

üst 1c7b7f7f
...@@ -3484,29 +3484,31 @@ class TimedRotatingFileHandlerTest(BaseFileTest): ...@@ -3484,29 +3484,31 @@ class TimedRotatingFileHandlerTest(BaseFileTest):
def test_rollover(self): def test_rollover(self):
fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S', fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S',
backupCount=1) backupCount=1)
r = logging.makeLogRecord({'msg': 'testing'}) try:
fh.emit(r) r = logging.makeLogRecord({'msg': 'testing'})
self.assertLogFile(self.fn) fh.emit(r)
time.sleep(1.0) self.assertLogFile(self.fn)
fh.emit(r) time.sleep(1.0)
now = datetime.datetime.now() fh.emit(r)
prevsec = now - datetime.timedelta(seconds=1) now = datetime.datetime.now()
earlier = now - datetime.timedelta(seconds=2) prevsec = now - datetime.timedelta(seconds=1)
fn1 = self.fn + prevsec.strftime(".%Y-%m-%d_%H-%M-%S") earlier = now - datetime.timedelta(seconds=2)
fn2 = self.fn + earlier.strftime(".%Y-%m-%d_%H-%M-%S") fn1 = self.fn + prevsec.strftime(".%Y-%m-%d_%H-%M-%S")
success = os.path.exists(fn1) or os.path.exists(fn2) fn2 = self.fn + earlier.strftime(".%Y-%m-%d_%H-%M-%S")
if not success: success = os.path.exists(fn1) or os.path.exists(fn2)
# print additional diagnostic information if not success:
print('Neither %s nor %s exists' % (fn1, fn2), file=sys.stderr) # print additional diagnostic information
dirname = os.path.dirname(fn1) print('Neither %s nor %s exists' % (fn1, fn2), file=sys.stderr)
files = os.listdir(dirname) dirname = os.path.dirname(fn1)
files = [f for f in files if f.startswith('test_logging-2-')] files = os.listdir(dirname)
print('matching files: %s' % files, file=sys.stderr) files = [f for f in files if f.startswith('test_logging-2-')]
self.assertTrue(success) print('matching files: %s' % files, file=sys.stderr)
for fn in (fn1, fn2): self.assertTrue(success)
if os.path.exists(fn): for fn in (fn1, fn2):
self.rmfiles.append(fn) if os.path.exists(fn):
self.rmfiles.append(fn)
finally:
fh.close()
def test_invalid(self): def test_invalid(self):
assertRaises = self.assertRaises assertRaises = self.assertRaises
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment