From: Ezio Melotti Date: Sat, 7 May 2011 16:50:28 +0000 (+0300) Subject: #5421: merge with 3.1. X-Git-Tag: v3.2.1b1~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4c1aebd88bc71fcbca26279bd21f971f93acb641;p=thirdparty%2FPython%2Fcpython.git #5421: merge with 3.1. --- 4c1aebd88bc71fcbca26279bd21f971f93acb641 diff --cc Lib/test/test_socket.py index e745502fce7f,6a9497bc7d2f..a948541825ab --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@@ -295,6 -274,36 +295,50 @@@ class GeneralModuleTests(unittest.TestC 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): ++ with self.assertRaises(TypeError) as cm: + s.sendto('\u2620', sockname) - with self.assertRaises(TypeError): ++ self.assertEqual(str(cm.exception), ++ "'str' does not support the buffer interface") ++ with self.assertRaises(TypeError) as cm: + s.sendto(5j, sockname) - with self.assertRaises(TypeError): ++ 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): ++ with self.assertRaises(TypeError) as cm: + s.sendto('\u2620', 0, sockname) - with self.assertRaises(TypeError): ++ self.assertEqual(str(cm.exception), ++ "'str' does not support the buffer interface") ++ with self.assertRaises(TypeError) as cm: + s.sendto(5j, 0, sockname) - with self.assertRaises(TypeError): ++ self.assertEqual(str(cm.exception), ++ "'complex' does not support the buffer interface") ++ with self.assertRaises(TypeError) as cm: + s.sendto(b'foo', 0, None) - with self.assertRaises(TypeError): ++ self.assertIn('not NoneType', str(cm.exception)) ++ with self.assertRaises(TypeError) as cm: + s.sendto(b'foo', 'bar', sockname) - with self.assertRaises(TypeError): ++ 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): ++ with self.assertRaises(TypeError) as cm: + s.sendto(b'foo') - with self.assertRaises(TypeError): ++ 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