[Python-checkins] r85971 - python/branches/py3k/Lib/test/test_logging.py

vinay.sajip python-checkins at python.org
Sat Oct 30 11:50:18 CEST 2010


Author: vinay.sajip
Date: Sat Oct 30 11:50:18 2010
New Revision: 85971

Log:
Remove ResourceWarnings caused by files left open.

Modified:
   python/branches/py3k/Lib/test/test_logging.py

Modified: python/branches/py3k/Lib/test/test_logging.py
==============================================================================
--- python/branches/py3k/Lib/test/test_logging.py	(original)
+++ python/branches/py3k/Lib/test/test_logging.py	Sat Oct 30 11:50:18 2010
@@ -907,7 +907,7 @@
     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 @@
 
     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 @@
         # 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 @@
         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 @@
         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 @@
         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


More information about the Python-checkins mailing list