[Python-checkins] cpython (merge 3.1 -> 3.2): #5421: merge with 3.1.

ezio.melotti python-checkins at python.org
Sat May 7 18:51:59 CEST 2011


http://hg.python.org/cpython/rev/4b3352b49483
changeset:   69917:4b3352b49483
branch:      3.2
parent:      69911:db97968379dd
parent:      69916:9222c9d747c1
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Sat May 07 19:50:28 2011 +0300
summary:
  #5421: merge with 3.1.

files:
  Lib/test/test_socket.py |  44 +++++++++++++++++++++++++++++
  1 files changed, 44 insertions(+), 0 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
@@ -295,6 +295,50 @@
         self.assertRaises(socket.error, raise_gaierror,
                               "Error raising socket exception.")
 
+    def testSendtoErrors(self):
+        # Testing that sendto doens't masks failures. See #10169.
+        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        self.addCleanup(s.close)
+        s.bind(('', 0))
+        sockname = s.getsockname()
+        # 2 args
+        with self.assertRaises(TypeError) as cm:
+            s.sendto('\u2620', sockname)
+        self.assertEqual(str(cm.exception),
+                         "'str' does not support the buffer interface")
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(5j, sockname)
+        self.assertEqual(str(cm.exception),
+                         "'complex' does not support the buffer interface")
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(b'foo', None)
+        self.assertIn('not NoneType',str(cm.exception))
+        # 3 args
+        with self.assertRaises(TypeError) as cm:
+            s.sendto('\u2620', 0, sockname)
+        self.assertEqual(str(cm.exception),
+                         "'str' does not support the buffer interface")
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(5j, 0, sockname)
+        self.assertEqual(str(cm.exception),
+                         "'complex' does not support the buffer interface")
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(b'foo', 0, None)
+        self.assertIn('not NoneType', str(cm.exception))
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(b'foo', 'bar', sockname)
+        self.assertIn('an integer is required', str(cm.exception))
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(b'foo', None, None)
+        self.assertIn('an integer is required', str(cm.exception))
+        # wrong number of args
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(b'foo')
+        self.assertIn('(1 given)', str(cm.exception))
+        with self.assertRaises(TypeError) as cm:
+            s.sendto(b'foo', 0, sockname, 4)
+        self.assertIn('(4 given)', str(cm.exception))
+
     def testCrucialConstants(self):
         # Testing for mission critical constants
         socket.AF_INET

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


More information about the Python-checkins mailing list