(self)
| 1471 | @unittest.skipUnless(hasattr(socket, 'inet_ntop'), |
| 1472 | 'test needs socket.inet_ntop()') |
| 1473 | def testStringToIPv6(self): |
| 1474 | try: |
| 1475 | from socket import inet_ntop, AF_INET6, has_ipv6 |
| 1476 | if not has_ipv6: |
| 1477 | self.skipTest('IPv6 not available') |
| 1478 | except ImportError: |
| 1479 | self.skipTest('could not import needed symbols from socket') |
| 1480 | |
| 1481 | if sys.platform == "win32": |
| 1482 | try: |
| 1483 | inet_ntop(AF_INET6, b'\x00' * 16) |
| 1484 | except OSError as e: |
| 1485 | if e.winerror == 10022: |
| 1486 | self.skipTest('IPv6 might not be supported') |
| 1487 | |
| 1488 | f = lambda a: inet_ntop(AF_INET6, a) |
| 1489 | assertInvalid = lambda a: self.assertRaises( |
| 1490 | (OSError, ValueError), f, a |
| 1491 | ) |
| 1492 | |
| 1493 | self.assertEqual('::', f(b'\x00' * 16)) |
| 1494 | self.assertEqual('::1', f(b'\x00' * 15 + b'\x01')) |
| 1495 | self.assertEqual( |
| 1496 | 'aef:b01:506:1001:ffff:9997:55:170', |
| 1497 | f(b'\x0a\xef\x0b\x01\x05\x06\x10\x01\xff\xff\x99\x97\x00\x55\x01\x70') |
| 1498 | ) |
| 1499 | self.assertEqual('::1', f(bytearray(b'\x00' * 15 + b'\x01'))) |
| 1500 | |
| 1501 | assertInvalid(b'\x12' * 15) |
| 1502 | assertInvalid(b'\x12' * 17) |
| 1503 | assertInvalid(b'\x12' * 4) |
| 1504 | |
| 1505 | # XXX The following don't test module-level functionality... |
| 1506 |
nothing calls this directly
no test coverage detected