[Python-checkins] cpython: Streamlined logging tests by moving common code to a helper function.

vinay.sajip python-checkins at python.org
Fri Sep 27 19:41:34 CEST 2013


http://hg.python.org/cpython/rev/c01e5a572348
changeset:   85811:c01e5a572348
user:        Vinay Sajip <vinay_sajip at yahoo.co.uk>
date:        Fri Sep 27 18:41:12 2013 +0100
summary:
  Streamlined logging tests by moving common code to a helper function.

files:
  Lib/test/test_logging.py |  26 ++++++++++----------------
  1 files changed, 10 insertions(+), 16 deletions(-)


diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -1437,6 +1437,13 @@
         time.sleep(self.sock_hdlr.retryTime - now + 0.001)
         self.root_logger.error('Nor this')
 
+def _get_temp_domain_socket():
+    fd, fn = tempfile.mkstemp(prefix='test_logging_', suffix='.sock')
+    os.close(fd)
+    # just need a name - file can't be present, or we'll get an
+    # 'address already in use' error.
+    os.remove(fn)
+    return fn
 
 @unittest.skipUnless(threading, 'Threading required for this test.')
 class UnixSocketHandlerTest(SocketHandlerTest):
@@ -1447,10 +1454,7 @@
 
     def setUp(self):
         # override the definition in the base class
-        fd, self.address = tempfile.mkstemp(prefix='test_logging_',
-                                            suffix='.sock')
-        os.close(fd)
-        os.remove(self.address)     # just need a name - file can't be present
+        self.address = _get_temp_domain_socket()
         SocketHandlerTest.setUp(self)
 
     def tearDown(self):
@@ -1520,10 +1524,7 @@
 
     def setUp(self):
         # override the definition in the base class
-        fd, self.address = tempfile.mkstemp(prefix='test_logging_',
-                                            suffix='.sock')
-        os.close(fd)
-        os.remove(self.address)     # just need a name - file can't be present
+        self.address = _get_temp_domain_socket()
         DatagramHandlerTest.setUp(self)
 
     def tearDown(self):
@@ -1596,20 +1597,13 @@
 
     def setUp(self):
         # override the definition in the base class
-        fd, self.address = tempfile.mkstemp(prefix='test_logging_',
-                                            suffix='.sock')
-        os.close(fd)
-        os.remove(self.address)     # just need a name - file can't be present
+        self.address = _get_temp_domain_socket()
         SysLogHandlerTest.setUp(self)
 
     def tearDown(self):
         SysLogHandlerTest.tearDown(self)
         os.remove(self.address)
 
-#    def test_output(self):
-#        import pdb; pdb.set_trace()
-#        SysLogHandlerTest.test_output(self)
-
 @unittest.skipUnless(threading, 'Threading required for this test.')
 class HTTPHandlerTest(BaseTest):
     """Test for HTTPHandler."""

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list