diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-10-30 09:50:18 (GMT) |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-10-30 09:50:18 (GMT) |
commit | b046b807fac8c2ad0c52a4d9872f8b9ccfd58c5b (patch) | |
tree | ad3e5586f18af52f135bd1dc0d40e8b37b3733f0 | |
parent | cc2adbc693c669bb212ea90483600eb3d71349c3 (diff) | |
download | cpython-b046b807fac8c2ad0c52a4d9872f8b9ccfd58c5b.zip cpython-b046b807fac8c2ad0c52a4d9872f8b9ccfd58c5b.tar.gz cpython-b046b807fac8c2ad0c52a4d9872f8b9ccfd58c5b.tar.bz2 |
Remove ResourceWarnings caused by files left open.
-rw-r--r-- | Lib/test/test_logging.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 11e18d8..07c96e7 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -907,7 +907,7 @@ class EncodingTest(BaseTest): def test_encoding_plain_file(self): # In Python 2.x, a plain file object is treated as having no encoding. log = logging.getLogger("test") - fn = tempfile.mktemp(".log") + fn = tempfile.mktemp(".log", "test_logging-1-") # the non-ascii data we write to the log. data = "foo\x80" try: @@ -1932,7 +1932,7 @@ class BaseFileTest(BaseTest): def setUp(self): BaseTest.setUp(self) - self.fn = tempfile.mktemp(".log") + self.fn = tempfile.mktemp(".log", "test_logging-2-") self.rmfiles = [] def tearDown(self): @@ -1956,10 +1956,12 @@ class RotatingFileHandlerTest(BaseFileTest): # If maxbytes is zero rollover never occurs rh = logging.handlers.RotatingFileHandler(self.fn, maxBytes=0) self.assertFalse(rh.shouldRollover(None)) + rh.close() def test_should_rollover(self): rh = logging.handlers.RotatingFileHandler(self.fn, maxBytes=1) self.assertTrue(rh.shouldRollover(self.next_rec())) + rh.close() def test_file_created(self): # checks that the file is created and assumes it was created @@ -1968,6 +1970,7 @@ class RotatingFileHandlerTest(BaseFileTest): rh = logging.handlers.RotatingFileHandler(self.fn) rh.emit(self.next_rec()) self.assertLogFile(self.fn) + rh.close() def test_rollover_filenames(self): rh = logging.handlers.RotatingFileHandler( @@ -1979,6 +1982,7 @@ class RotatingFileHandlerTest(BaseFileTest): rh.emit(self.next_rec()) self.assertLogFile(self.fn + ".2") self.assertFalse(os.path.exists(self.fn + ".3")) + rh.close() class TimedRotatingFileHandlerTest(BaseFileTest): # test methods added below @@ -1998,6 +2002,7 @@ for when, exp in (('S', 1), rh = logging.handlers.TimedRotatingFileHandler( self.fn, when=when, interval=1, backupCount=0) self.assertEquals(exp, rh.computeRollover(0.0)) + rh.close() setattr(TimedRotatingFileHandlerTest, "test_compute_rollover_%s" % when, test_compute_rollover) # Set the locale to the platform-dependent default. I have no idea |