summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-05-07 16:51:47 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-05-07 16:51:47 (GMT)
commit8b7664d0b81b65acf1e1946adf22d72cfa2dff26 (patch)
treef50f3c9a69074d816a4f6c0df757515b53c5af4b /Lib/test
parent842e567530c957ca2344ff29f7bcea5d74d8d3d9 (diff)
parent4c1aebd88bc71fcbca26279bd21f971f93acb641 (diff)
downloadcpython-8b7664d0b81b65acf1e1946adf22d72cfa2dff26.zip
cpython-8b7664d0b81b65acf1e1946adf22d72cfa2dff26.tar.gz
cpython-8b7664d0b81b65acf1e1946adf22d72cfa2dff26.tar.bz2
#5421: merge with 3.2.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_socket.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 99d658b..8a6a780 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -283,6 +283,50 @@ class GeneralModuleTests(unittest.TestCase):
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