MCPcopy Index your code
hub / github.com/python/cpython / testSendtoErrors

Method testSendtoErrors

Lib/test/test_socket.py:988–1028  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

986 raise socket.gaierror
987
988 def testSendtoErrors(self):
989 # Testing that sendto doesn't mask failures. See #10169.
990 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
991 self.addCleanup(s.close)
992 s.bind(('', 0))
993 sockname = s.getsockname()
994 # 2 args
995 with self.assertRaises(TypeError) as cm:
996 s.sendto('\u2620', sockname)
997 self.assertEqual(str(cm.exception),
998 "a bytes-like object is required, not 'str'")
999 with self.assertRaises(TypeError) as cm:
1000 s.sendto(5j, sockname)
1001 self.assertEqual(str(cm.exception),
1002 "a bytes-like object is required, not 'complex'")
1003 with self.assertRaises(TypeError) as cm:
1004 s.sendto(b'foo', None)
1005 self.assertIn('not NoneType',str(cm.exception))
1006 # 3 args
1007 with self.assertRaises(TypeError) as cm:
1008 s.sendto('\u2620', 0, sockname)
1009 self.assertEqual(str(cm.exception),
1010 "a bytes-like object is required, not 'str'")
1011 with self.assertRaises(TypeError) as cm:
1012 s.sendto(5j, 0, sockname)
1013 self.assertEqual(str(cm.exception),
1014 "a bytes-like object is required, not 'complex'")
1015 with self.assertRaises(TypeError) as cm:
1016 s.sendto(b'foo', 0, None)
1017 self.assertIn('not NoneType', str(cm.exception))
1018 with self.assertRaises(TypeError) as cm:
1019 s.sendto(b'foo', 'bar', sockname)
1020 with self.assertRaises(TypeError) as cm:
1021 s.sendto(b'foo', None, None)
1022 # wrong number of args
1023 with self.assertRaises(TypeError) as cm:
1024 s.sendto(b'foo')
1025 self.assertIn('(1 given)', str(cm.exception))
1026 with self.assertRaises(TypeError) as cm:
1027 s.sendto(b'foo', 0, sockname, 4)
1028 self.assertIn('(4 given)', str(cm.exception))
1029
1030 def testCrucialConstants(self):
1031 # Testing for mission critical constants

Callers

nothing calls this directly

Calls 9

strFunction · 0.85
socketMethod · 0.80
addCleanupMethod · 0.80
assertInMethod · 0.80
bindMethod · 0.45
getsocknameMethod · 0.45
assertRaisesMethod · 0.45
sendtoMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected