(self)
| 1320 | self.assertRaises(OverflowError, socket.getservbyport, 65536) |
| 1321 | |
| 1322 | def testDefaultTimeout(self): |
| 1323 | # Testing default timeout |
| 1324 | # The default timeout should initially be None |
| 1325 | self.assertEqual(socket.getdefaulttimeout(), None) |
| 1326 | with socket.socket() as s: |
| 1327 | self.assertEqual(s.gettimeout(), None) |
| 1328 | |
| 1329 | # Set the default timeout to 10, and see if it propagates |
| 1330 | with socket_setdefaulttimeout(10.125): |
| 1331 | self.assertEqual(socket.getdefaulttimeout(), 10.125) |
| 1332 | with socket.socket() as sock: |
| 1333 | self.assertEqual(sock.gettimeout(), 10.125) |
| 1334 | |
| 1335 | socket.setdefaulttimeout(decimal.Decimal('11.125')) |
| 1336 | self.assertEqual(socket.getdefaulttimeout(), 11.125) |
| 1337 | with socket.socket() as sock: |
| 1338 | self.assertEqual(sock.gettimeout(), 11.125) |
| 1339 | |
| 1340 | socket.setdefaulttimeout(fractions.Fraction(97, 8)) |
| 1341 | self.assertEqual(socket.getdefaulttimeout(), 12.125) |
| 1342 | with socket.socket() as sock: |
| 1343 | self.assertEqual(sock.gettimeout(), 12.125) |
| 1344 | |
| 1345 | # Reset the default timeout to None, and see if it propagates |
| 1346 | socket.setdefaulttimeout(None) |
| 1347 | self.assertEqual(socket.getdefaulttimeout(), None) |
| 1348 | with socket.socket() as sock: |
| 1349 | self.assertEqual(sock.gettimeout(), None) |
| 1350 | |
| 1351 | # Check that setting it to an invalid value raises ValueError |
| 1352 | self.assertRaises(ValueError, socket.setdefaulttimeout, -1) |
| 1353 | |
| 1354 | # Check that setting it to an invalid type raises TypeError |
| 1355 | self.assertRaises(TypeError, socket.setdefaulttimeout, "spam") |
| 1356 | |
| 1357 | @unittest.skipUnless(hasattr(socket, 'inet_aton'), |
| 1358 | 'test needs socket.inet_aton()') |
nothing calls this directly
no test coverage detected