From da1a8f12d7a38f67f3f464aaaffa851f929ae4ea Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 19:45:09 +0200 Subject: Adding upstream version 0.10.1. Signed-off-by: Daniel Baumann --- netaddr/tests/ip/test_socket_module_fallback.py | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 netaddr/tests/ip/test_socket_module_fallback.py (limited to 'netaddr/tests/ip/test_socket_module_fallback.py') diff --git a/netaddr/tests/ip/test_socket_module_fallback.py b/netaddr/tests/ip/test_socket_module_fallback.py new file mode 100644 index 0000000..3174972 --- /dev/null +++ b/netaddr/tests/ip/test_socket_module_fallback.py @@ -0,0 +1,37 @@ +import pytest + +from netaddr.fbsocket import (inet_ntop, inet_pton, inet_ntoa, AF_INET6) + + +@pytest.mark.parametrize(('actual', 'expected'), [ + ('0:0:0:0:0:0:0:0', '::'), + ('0:0:0:0:0:0:0:A', '::a'), + ('A:0:0:0:0:0:0:0', 'a::'), + ('A:0:A:0:0:0:0:0', 'a:0:a::'), + ('A:0:0:0:0:0:0:A', 'a::a'), + ('0:A:0:0:0:0:0:A', '0:a::a'), + ('A:0:A:0:0:0:0:A', 'a:0:a::a'), + ('0:0:0:A:0:0:0:A', '::a:0:0:0:a'), + ('0:0:0:0:A:0:0:A', '::a:0:0:a'), + ('A:0:0:0:0:A:0:A', 'a::a:0:a'), + ('A:0:0:A:0:0:A:0', 'a::a:0:0:a:0'), + ('A:0:A:0:A:0:A:0', 'a:0:a:0:a:0:a:0'), + ('0:A:0:A:0:A:0:A', '0:a:0:a:0:a:0:a'), + ('1080:0:0:0:8:800:200C:417A', '1080::8:800:200c:417a'), + ('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', 'fedc:ba98:7654:3210:fedc:ba98:7654:3210'), +]) +def test_inet_ntop_and_inet_pton_ipv6_conversion(actual, expected): + assert inet_ntop(AF_INET6, inet_pton(AF_INET6, actual)) == expected + + +def test_inet_ntoa_ipv4_exceptions(): + with pytest.raises(TypeError): + inet_ntoa(1) + + with pytest.raises(ValueError): + inet_ntoa('\x00') + + +def test_inet_pton_ipv6_exceptions(): + with pytest.raises(ValueError): + inet_pton(AF_INET6, '::0x07f') -- cgit v1.2.3