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

Method testIPv4toString

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

Source from the content-addressed store, hash-verified

1348 @unittest.skipUnless(hasattr(socket, 'inet_pton'),
1349 'test needs socket.inet_pton()')
1350 def testIPv4toString(self):
1351 from socket import inet_aton as f, inet_pton, AF_INET
1352 g = lambda a: inet_pton(AF_INET, a)
1353
1354 assertInvalid = lambda func,a: self.assertRaises(
1355 (OSError, ValueError), func, a
1356 )
1357
1358 self.assertEqual(b'\x00\x00\x00\x00', f('0.0.0.0'))
1359 self.assertEqual(b'\xff\x00\xff\x00', f('255.0.255.0'))
1360 self.assertEqual(b'\xaa\xaa\xaa\xaa', f('170.170.170.170'))
1361 self.assertEqual(b'\x01\x02\x03\x04', f('1.2.3.4'))
1362 self.assertEqual(b'\xff\xff\xff\xff', f('255.255.255.255'))
1363 # bpo-29972: inet_pton() doesn't fail on AIX
1364 if not AIX:
1365 assertInvalid(f, '0.0.0.')
1366 assertInvalid(f, '300.0.0.0')
1367 assertInvalid(f, 'a.0.0.0')
1368 assertInvalid(f, '1.2.3.4.5')
1369 assertInvalid(f, '::1')
1370
1371 self.assertEqual(b'\x00\x00\x00\x00', g('0.0.0.0'))
1372 self.assertEqual(b'\xff\x00\xff\x00', g('255.0.255.0'))
1373 self.assertEqual(b'\xaa\xaa\xaa\xaa', g('170.170.170.170'))
1374 self.assertEqual(b'\xff\xff\xff\xff', g('255.255.255.255'))
1375 assertInvalid(g, '0.0.0.')
1376 assertInvalid(g, '300.0.0.0')
1377 assertInvalid(g, 'a.0.0.0')
1378 assertInvalid(g, '1.2.3.4.5')
1379 assertInvalid(g, '::1')
1380
1381 @unittest.skipUnless(hasattr(socket, 'inet_pton'),
1382 'test needs socket.inet_pton()')

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected