diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-05-06 06:19:41 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2011-05-06 06:19:41 (GMT) |
commit | 89c8862ee5f6584f6a89eb40ab03fae625a11dc9 (patch) | |
tree | 505f162866b3865178c528350951a85594884b8a /Lib | |
parent | 1c7b7f7fbeb79eaddcd21b20a43802db0f7790a1 (diff) | |
download | cpython-89c8862ee5f6584f6a89eb40ab03fae625a11dc9.zip cpython-89c8862ee5f6584f6a89eb40ab03fae625a11dc9.tar.gz cpython-89c8862ee5f6584f6a89eb40ab03fae625a11dc9.tar.bz2 |
Close handler opened in test.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_logging.py | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index ff9eb66..919f0b2 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3484,29 +3484,31 @@ class TimedRotatingFileHandlerTest(BaseFileTest): def test_rollover(self): fh = logging.handlers.TimedRotatingFileHandler(self.fn, 'S', backupCount=1) - r = logging.makeLogRecord({'msg': 'testing'}) - fh.emit(r) - self.assertLogFile(self.fn) - time.sleep(1.0) - fh.emit(r) - now = datetime.datetime.now() - prevsec = now - datetime.timedelta(seconds=1) - earlier = now - datetime.timedelta(seconds=2) - fn1 = self.fn + prevsec.strftime(".%Y-%m-%d_%H-%M-%S") - fn2 = self.fn + earlier.strftime(".%Y-%m-%d_%H-%M-%S") - success = os.path.exists(fn1) or os.path.exists(fn2) - if not success: - # print additional diagnostic information - print('Neither %s nor %s exists' % (fn1, fn2), file=sys.stderr) - dirname = os.path.dirname(fn1) - files = os.listdir(dirname) - files = [f for f in files if f.startswith('test_logging-2-')] - print('matching files: %s' % files, file=sys.stderr) - self.assertTrue(success) - for fn in (fn1, fn2): - if os.path.exists(fn): - self.rmfiles.append(fn) - + try: + r = logging.makeLogRecord({'msg': 'testing'}) + fh.emit(r) + self.assertLogFile(self.fn) + time.sleep(1.0) + fh.emit(r) + now = datetime.datetime.now() + prevsec = now - datetime.timedelta(seconds=1) + earlier = now - datetime.timedelta(seconds=2) + fn1 = self.fn + prevsec.strftime(".%Y-%m-%d_%H-%M-%S") + fn2 = self.fn + earlier.strftime(".%Y-%m-%d_%H-%M-%S") + success = os.path.exists(fn1) or os.path.exists(fn2) + if not success: + # print additional diagnostic information + print('Neither %s nor %s exists' % (fn1, fn2), file=sys.stderr) + dirname = os.path.dirname(fn1) + files = os.listdir(dirname) + files = [f for f in files if f.startswith('test_logging-2-')] + print('matching files: %s' % files, file=sys.stderr) + self.assertTrue(success) + for fn in (fn1, fn2): + if os.path.exists(fn): + self.rmfiles.append(fn) + finally: + fh.close() def test_invalid(self): assertRaises = self.assertRaises |