netaddr / netaddr

A network address manipulation library for Python
https://netaddr.readthedocs.io/en/latest/
Other
786 stars 177 forks source link

Test failure on musl #381

Closed TinfoilSubmarine closed 6 months ago

TinfoilSubmarine commented 7 months ago
============================ test session starts ==============================
platform linux -- Python 3.12.3, pytest-7.4.3, pluggy-1.3.0
rootdir: /builddir/python3-netaddr-1.2.1
configfile: pytest.ini
collected 348 items

docs/source/tutorial_01.rst F                                            [  0%]
docs/source/tutorial_02.rst .                                            [  0%]
docs/source/tutorial_03.rst F                                            [  0%]
netaddr/ip/__init__.py ....                                              [  2%]
netaddr/strategy/ipv4.py .                                               [  2%]
netaddr/tests/test_netaddr.py ..                                         [  2%]
netaddr/tests/core/test_pubsub.py .                                      [  3%]
netaddr/tests/eui/test_eui.py ..........................                 [ 10%]
netaddr/tests/eui/test_ieee_parsers.py ..                                [ 11%]
netaddr/tests/ip/test_cidr_v4.py .........                               [ 13%]
netaddr/tests/ip/test_cidr_v6.py ....                                    [ 14%]
netaddr/tests/ip/test_dns.py ..                                          [ 15%]
netaddr/tests/ip/test_ip.py ....                                         [ 16%]
netaddr/tests/ip/test_ip_categories.py ................................. [ 26%]
.........................                                                [ 33%]
netaddr/tests/ip/test_ip_comparisons.py ..                               [ 33%]
netaddr/tests/ip/test_ip_globs.py ........                               [ 36%]
netaddr/tests/ip/test_ip_network_categories.py ....                      [ 37%]
netaddr/tests/ip/test_ip_ranges.py ................                      [ 41%]
netaddr/tests/ip/test_ip_rfc1924.py .                                    [ 42%]
netaddr/tests/ip/test_ip_sets.py .............................           [ 50%]
netaddr/tests/ip/test_ip_splitter.py ....                                [ 51%]
netaddr/tests/ip/test_ip_v4.py ......................................... [ 63%]
............                                                             [ 66%]
netaddr/tests/ip/test_ip_v4_v6_conversions.py .....                      [ 68%]
netaddr/tests/ip/test_ip_v6.py ..............                            [ 72%]
netaddr/tests/ip/test_network_ops.py ...                                 [ 73%]
netaddr/tests/ip/test_nmap.py ......                                     [ 75%]
netaddr/tests/ip/test_old_specs.py ...                                   [ 75%]
netaddr/tests/ip/test_platform_osx.py s.                                 [ 76%]
netaddr/tests/ip/test_socket_module_fallback.py ..................       [ 81%]
netaddr/tests/strategy/test_eui48_strategy.py ..                         [ 82%]
netaddr/tests/strategy/test_ipv4_strategy.py .............               [ 85%]
netaddr/tests/strategy/test_ipv6_strategy.py F.......................... [ 93%]
....................F.                                                   [100%]

=================================== FAILURES ===================================
__________________________ [doctest] tutorial_01.rst ___________________________
192 IPAddress('192.0.2.15')
193 >>> ip = IPAddress('192.0.2.15').ipv6()
194 >>> ip
195 IPAddress('::ffff:192.0.2.15')
196 >>> ip.is_ipv4_mapped()
197 True
198 >>> ip.is_ipv4_compat()
199 False
200 
201 >>> IPAddress('192.0.2.15').ipv6(ipv4_compatible=True)
Expected:
    IPAddress('::192.0.2.15')
Got:
    IPAddress('::c000:20f')

/builddir/python3-netaddr-1.2.1/docs/source/tutorial_01.rst:201: DocTestFailure
__________________________ [doctest] tutorial_03.rst ___________________________
039 >>> IPSet(IPSet(['192.0.2.0/32']))
040 IPSet(['192.0.2.0/32'])
041 >>> IPSet(IPRange("10.0.0.0", "10.0.1.31"))
042 IPSet(['10.0.0.0/24', '10.0.1.0/27'])
043 >>> IPSet(IPRange('0.0.0.0', '255.255.255.255'))
044 IPSet(['0.0.0.0/0'])
045 
046 You can iterate over all the IP addresses that are members of the IP set.
047 
048 >>> for ip in IPSet(['192.0.2.0/28', '::192.0.2.0/124']):
Differences (unified diff with -expected +actual):
    @@ -15,18 +15,18 @@
     192.0.2.14
     192.0.2.15
    -::192.0.2.0
    -::192.0.2.1
    -::192.0.2.2
    -::192.0.2.3
    -::192.0.2.4
    -::192.0.2.5
    -::192.0.2.6
    -::192.0.2.7
    -::192.0.2.8
    -::192.0.2.9
    -::192.0.2.10
    -::192.0.2.11
    -::192.0.2.12
    -::192.0.2.13
    -::192.0.2.14
    -::192.0.2.15
    +::c000:200
    +::c000:201
    +::c000:202
    +::c000:203
    +::c000:204
    +::c000:205
    +::c000:206
    +::c000:207
    +::c000:208
    +::c000:209
    +::c000:20a
    +::c000:20b
    +::c000:20c
    +::c000:20d
    +::c000:20e
    +::c000:20f

/builddir/python3-netaddr-1.2.1/docs/source/tutorial_03.rst:48: DocTestFailure
______________________________ test_strategy_ipv6 ______________________________

    def test_strategy_ipv6():
        b = '0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:1111111111111111:1111111111111110'
        i = 4294967294
        t = (0, 0, 0, 0, 0, 0, 0xFFFF, 0xFFFE)
        s = '::255.255.255.254'
        p = b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xfe'

        assert ipv6.bits_to_int(b) == i
        assert ipv6.int_to_bits(i) == b

>       assert ipv6.int_to_str(i) == s
E       AssertionError: assert '::ffff:fffe' == '::255.255.255.254'
E         - ::255.255.255.254
E         + ::ffff:fffe

netaddr/tests/strategy/test_ipv6_strategy.py:19: AssertionError
_______ test_strategy_ipv6_mapped_and_compatible_ipv4_string_formatting ________

    def test_strategy_ipv6_mapped_and_compatible_ipv4_string_formatting():
>       assert ipv6.int_to_str(0xFFFFFF) == '::0.255.255.255'
E       AssertionError: assert '::ff:ffff' == '::0.255.255.255'
E         - ::0.255.255.255
E         + ::ff:ffff

netaddr/tests/strategy/test_ipv6_strategy.py:129: AssertionError
=========================== short test summary info ============================
FAILED docs/source/tutorial_01.rst::tutorial_01.rst
FAILED docs/source/tutorial_03.rst::tutorial_03.rst
FAILED netaddr/tests/strategy/test_ipv6_strategy.py::test_strategy_ipv6 - Ass...
FAILED netaddr/tests/strategy/test_ipv6_strategy.py::test_strategy_ipv6_mapped_and_compatible_ipv4_string_formatting
=================== 4 failed, 343 passed, 1 skipped in 1.10s ===================

Looks similar to https://github.com/netaddr/netaddr/blob/master/netaddr/tests/strategy/test_ipv6_strategy.py#L142-L148

jstasiak commented 7 months ago

Looks similar to https://github.com/netaddr/netaddr/blob/master/netaddr/tests/strategy/test_ipv6_strategy.py#L142-L148

Permalink: https://github.com/netaddr/netaddr/blob/2c89b344a8e402773cab569ea9e522b1d683109c/netaddr/tests/strategy/test_ipv6_strategy.py#L142-L148

TinfoilSubmarine commented 7 months ago

This is due to socket.inet_ntop returning different values on different systems. I just tested on glibc and musl Linux, as well as Windows, and can confirm that inet_ntop is to "blame" for this.

jstasiak commented 7 months ago

Oh yeah it's gonna be 100% that. Short-term I'm happy to accept a PR that makes the test pass conditionally on musl by expecting the other value, although it's not clear to me how one would detect musl.

Long-term I think netaddr should make it possible to produce a stable text representation and an implementation-dependent one (which one by default – not sure at this stage).

jstasiak commented 6 months ago

What does this return on your machine @TinfoilSubmarine?

python -c 'import platform; print(platform.libc_ver())'
TinfoilSubmarine commented 6 months ago

What does this return on your machine @TinfoilSubmarine?

python -c 'import platform; print(platform.libc_ver())'
$ python -c 'import platform; print(platform.libc_ver())'
('libc', '')
jstasiak commented 6 months ago

Thank you. One more question, do you mind installing packaging and providing the output of python -c 'from packaging.tags import sys_tags; print(list(sys_tags()))'? I'm trying to figure out the best way to make this test conditional.

TinfoilSubmarine commented 6 months ago

Thank you. One more question, do you mind installing packaging and providing the output of python -c 'from packaging.tags import sys_tags; print(list(sys_tags()))'? I'm trying to figure out the best way to make this test conditional.

$ python -c 'from packaging.tags import sys_tags; print(list(sys_tags()))'
[<cp312-cp312-musllinux_1_1_x86_64 @ 139937041473344>, <cp312-cp312-musllinux_1_0_x86_64 @ 139937041566976>, <cp312-cp312-linux_x86_64 @ 139937041567104>, <cp312-abi3-musllinux_1_1_x86_64 @ 139937041567488>, <cp312-abi3-musllinux_1_0_x86_64 @ 139937041567424>, <cp312-abi3-linux_x86_64 @ 139937041567296>, <cp312-none-musllinux_1_1_x86_64 @ 139937041567744>, <cp312-none-musllinux_1_0_x86_64 @ 139937041567616>, <cp312-none-linux_x86_64 @ 139937041567872>, <cp311-abi3-musllinux_1_1_x86_64 @ 139937043503744>, <cp311-abi3-musllinux_1_0_x86_64 @ 139937041568064>, <cp311-abi3-linux_x86_64 @ 139937041568192>, <cp310-abi3-musllinux_1_1_x86_64 @ 139937041568320>, <cp310-abi3-musllinux_1_0_x86_64 @ 139937041568448>, <cp310-abi3-linux_x86_64 @ 139937041568576>, <cp39-abi3-musllinux_1_1_x86_64 @ 139937041568704>, <cp39-abi3-musllinux_1_0_x86_64 @ 139937041568832>, <cp39-abi3-linux_x86_64 @ 139937041568960>, <cp38-abi3-musllinux_1_1_x86_64 @ 139937041569088>, <cp38-abi3-musllinux_1_0_x86_64 @ 139937041569216>, <cp38-abi3-linux_x86_64 @ 139937041569344>, <cp37-abi3-musllinux_1_1_x86_64 @ 139937041569472>, <cp37-abi3-musllinux_1_0_x86_64 @ 139937041569600>, <cp37-abi3-linux_x86_64 @ 139937041569728>, <cp36-abi3-musllinux_1_1_x86_64 @ 139937041569856>, <cp36-abi3-musllinux_1_0_x86_64 @ 139937041569984>, <cp36-abi3-linux_x86_64 @ 139937041570112>, <cp35-abi3-musllinux_1_1_x86_64 @ 139937041570240>, <cp35-abi3-musllinux_1_0_x86_64 @ 139937041570368>, <cp35-abi3-linux_x86_64 @ 139937041570496>, <cp34-abi3-musllinux_1_1_x86_64 @ 139937041570624>, <cp34-abi3-musllinux_1_0_x86_64 @ 139937041570752>, <cp34-abi3-linux_x86_64 @ 139937041570880>, <cp33-abi3-musllinux_1_1_x86_64 @ 139937041571008>, <cp33-abi3-musllinux_1_0_x86_64 @ 139937041571136>, <cp33-abi3-linux_x86_64 @ 139937041571264>, <cp32-abi3-musllinux_1_1_x86_64 @ 139937041571392>, <cp32-abi3-musllinux_1_0_x86_64 @ 139937041571520>, <cp32-abi3-linux_x86_64 @ 139937041571648>, <py312-none-musllinux_1_1_x86_64 @ 139937041473920>, <py312-none-musllinux_1_0_x86_64 @ 139937041571968>, <py312-none-linux_x86_64 @ 139937041572096>, <py3-none-musllinux_1_1_x86_64 @ 139937041572224>, <py3-none-musllinux_1_0_x86_64 @ 139937041572352>, <py3-none-linux_x86_64 @ 139937041572480>, <py311-none-musllinux_1_1_x86_64 @ 139937041572608>, <py311-none-musllinux_1_0_x86_64 @ 139937041572736>, <py311-none-linux_x86_64 @ 139937041572864>, <py310-none-musllinux_1_1_x86_64 @ 139937041572992>, <py310-none-musllinux_1_0_x86_64 @ 139937041573120>, <py310-none-linux_x86_64 @ 139937041573248>, <py39-none-musllinux_1_1_x86_64 @ 139937041573376>, <py39-none-musllinux_1_0_x86_64 @ 139937041573504>, <py39-none-linux_x86_64 @ 139937041573632>, <py38-none-musllinux_1_1_x86_64 @ 139937041573760>, <py38-none-musllinux_1_0_x86_64 @ 139937041573888>, <py38-none-linux_x86_64 @ 139937041574016>, <py37-none-musllinux_1_1_x86_64 @ 139937041574144>, <py37-none-musllinux_1_0_x86_64 @ 139937041574272>, <py37-none-linux_x86_64 @ 139937041574400>, <py36-none-musllinux_1_1_x86_64 @ 139937041574528>, <py36-none-musllinux_1_0_x86_64 @ 139937041574656>, <py36-none-linux_x86_64 @ 139937041574784>, <py35-none-musllinux_1_1_x86_64 @ 139937041574912>, <py35-none-musllinux_1_0_x86_64 @ 139937041575040>, <py35-none-linux_x86_64 @ 139937041575168>, <py34-none-musllinux_1_1_x86_64 @ 139937041575296>, <py34-none-musllinux_1_0_x86_64 @ 139937041575424>, <py34-none-linux_x86_64 @ 139937041575552>, <py33-none-musllinux_1_1_x86_64 @ 139937041575680>, <py33-none-musllinux_1_0_x86_64 @ 139937041575808>, <py33-none-linux_x86_64 @ 139937041575936>, <py32-none-musllinux_1_1_x86_64 @ 139937041576064>, <py32-none-musllinux_1_0_x86_64 @ 139937041576192>, <py32-none-linux_x86_64 @ 139937041576320>, <py31-none-musllinux_1_1_x86_64 @ 139937041576448>, <py31-none-musllinux_1_0_x86_64 @ 139937041576576>, <py31-none-linux_x86_64 @ 139937041576704>, <py30-none-musllinux_1_1_x86_64 @ 139937041576832>, <py30-none-musllinux_1_0_x86_64 @ 139937041576960>, <py30-none-linux_x86_64 @ 139937041577088>, <cp312-none-any @ 139937041577216>, <py312-none-any @ 139937041577280>, <py3-none-any @ 139937041577344>, <py311-none-any @ 139937041577408>, <py310-none-any @ 139937041577472>, <py39-none-any @ 139937041577536>, <py38-none-any @ 139937041577600>, <py37-none-any @ 139937041577664>, <py36-none-any @ 139937041577728>, <py35-none-any @ 139937041577792>, <py34-none-any @ 139937041577856>, <py33-none-any @ 139937041577920>, <py32-none-any @ 139937041577984>, <py31-none-any @ 139937041578048>, <py30-none-any @ 139937041578112>]
jstasiak commented 6 months ago

The fix for this has been released in netaddr 1.3.0.