[Python-checkins] cpython: Refactor buggy test to correctly use the msg argument of assertRaises.

ezio.melotti python-checkins at python.org
Sun May 8 19:24:07 CEST 2011


http://hg.python.org/cpython/rev/9af64d83c217
changeset:   69940:9af64d83c217
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sun May 08 20:23:57 2011 +0300
summary:
  Refactor buggy test to correctly use the msg argument of assertRaises.

files:
  Lib/test/test_socket.py |  13 ++++---------
  1 files changed, 4 insertions(+), 9 deletions(-)


diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -270,18 +270,13 @@
 
     def testSocketError(self):
         # Testing socket module exceptions
-        def raise_error(*args, **kwargs):
+        msg = "Error raising socket exception (%s)."
+        with self.assertRaises(socket.error, msg=msg % 'socket.error'):
             raise socket.error
-        def raise_herror(*args, **kwargs):
+        with self.assertRaises(socket.error, msg=msg % 'socket.herror'):
             raise socket.herror
-        def raise_gaierror(*args, **kwargs):
+        with self.assertRaises(socket.error, msg=msg % 'socket.gaierror'):
             raise socket.gaierror
-        self.assertRaises(socket.error, raise_error,
-                              "Error raising socket exception.")
-        self.assertRaises(socket.error, raise_herror,
-                              "Error raising socket exception.")
-        self.assertRaises(socket.error, raise_gaierror,
-                              "Error raising socket exception.")
 
     def testSendtoErrors(self):
         # Testing that sendto doens't masks failures. See #10169.

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


More information about the Python-checkins mailing list