diff options
author | Éric Araujo <merwok@netwok.org> | 2011-05-25 18:06:35 +0200 |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-05-25 18:06:35 +0200 |
commit | de32c4b97caa7e4b70b81c18da3fa693bebb952d (patch) | |
tree | b771908fe89fc117032c503fa3e37c5f893bdb75 /Lib/test/test_socket.py | |
parent | 1c814933dad1bea8eff9fbb8c39064d6de379a8d (diff) | |
parent | 3db5f1d86143ce3b24f187b170b19fe639af000c (diff) | |
download | cpython-de32c4b97caa7e4b70b81c18da3fa693bebb952d.tar.gz |
Branch merge
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r-- | Lib/test/test_socket.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index d41bca51b5..12e09dddeb 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -274,6 +274,45 @@ 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(UnicodeEncodeError): + s.sendto(u'\u2620', sockname) + with self.assertRaises(TypeError) as cm: + s.sendto(5j, sockname) + self.assertIn('not complex', str(cm.exception)) + with self.assertRaises(TypeError) as cm: + s.sendto('foo', None) + self.assertIn('not NoneType', str(cm.exception)) + # 3 args + with self.assertRaises(UnicodeEncodeError): + s.sendto(u'\u2620', 0, sockname) + with self.assertRaises(TypeError) as cm: + s.sendto(5j, 0, sockname) + self.assertIn('not complex', str(cm.exception)) + with self.assertRaises(TypeError) as cm: + s.sendto('foo', 0, None) + self.assertIn('not NoneType', str(cm.exception)) + with self.assertRaises(TypeError) as cm: + s.sendto('foo', 'bar', sockname) + self.assertIn('an integer is required', str(cm.exception)) + with self.assertRaises(TypeError) as cm: + s.sendto('foo', None, None) + self.assertIn('an integer is required', str(cm.exception)) + # wrong number of args + with self.assertRaises(TypeError) as cm: + s.sendto('foo') + self.assertIn('(1 given)', str(cm.exception)) + with self.assertRaises(TypeError) as cm: + s.sendto('foo', 0, sockname, 4) + self.assertIn('(4 given)', str(cm.exception)) + + def testCrucialConstants(self): # Testing for mission critical constants socket.AF_INET @@ -661,6 +700,13 @@ class GeneralModuleTests(unittest.TestCase): def test_sendall_interrupted_with_timeout(self): self.check_sendall_interrupted(True) + def testListenBacklog0(self): + srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + srv.bind((HOST, 0)) + # backlog = 0 + srv.listen(0) + srv.close() + @unittest.skipUnless(thread, 'Threading required for this test.') class BasicTCPTest(SocketConnectedTest): |