MCPcopy Index your code
hub / github.com/RustPython/RustPython / testStringToIPv4

Method testStringToIPv4

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

Source from the content-addressed store, hash-verified

1445 @unittest.skipUnless(hasattr(socket, 'inet_ntop'),
1446 'test needs socket.inet_ntop()')
1447 def testStringToIPv4(self):
1448 from socket import inet_ntoa as f, inet_ntop, AF_INET
1449 g = lambda a: inet_ntop(AF_INET, a)
1450 assertInvalid = lambda func,a: self.assertRaises(
1451 (OSError, ValueError), func, a
1452 )
1453
1454 self.assertEqual('1.0.1.0', f(b'\x01\x00\x01\x00'))
1455 self.assertEqual('170.85.170.85', f(b'\xaa\x55\xaa\x55'))
1456 self.assertEqual('255.255.255.255', f(b'\xff\xff\xff\xff'))
1457 self.assertEqual('1.2.3.4', f(b'\x01\x02\x03\x04'))
1458 assertInvalid(f, b'\x00' * 3)
1459 assertInvalid(f, b'\x00' * 5)
1460 assertInvalid(f, b'\x00' * 16)
1461 self.assertEqual('170.85.170.85', f(bytearray(b'\xaa\x55\xaa\x55')))
1462
1463 self.assertEqual('1.0.1.0', g(b'\x01\x00\x01\x00'))
1464 self.assertEqual('170.85.170.85', g(b'\xaa\x55\xaa\x55'))
1465 self.assertEqual('255.255.255.255', g(b'\xff\xff\xff\xff'))
1466 assertInvalid(g, b'\x00' * 3)
1467 assertInvalid(g, b'\x00' * 5)
1468 assertInvalid(g, b'\x00' * 16)
1469 self.assertEqual('170.85.170.85', g(bytearray(b'\xaa\x55\xaa\x55')))
1470
1471 @unittest.skipUnless(hasattr(socket, 'inet_ntop'),
1472 'test needs socket.inet_ntop()')

Callers

nothing calls this directly

Calls 5

inet_ntopFunction · 0.90
fFunction · 0.70
gFunction · 0.70
assertRaisesMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected