Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure on musl #381

Closed
TinfoilSubmarine opened this issue May 1, 2024 · 8 comments · Fixed by #387
Closed

Test failure on musl #381

TinfoilSubmarine opened this issue May 1, 2024 · 8 comments · Fixed by #387

Comments

@TinfoilSubmarine
Copy link

============================ 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
Copy link
Contributor

jstasiak commented May 1, 2024

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

Permalink:

# So this is strange. Even though on Windows we get decimal notation in a lot of the addresses above,
# in case of 0.0.0.0 we get hex instead. Worth investigating, putting
# the conditional assert here for now to make this visible.
if platform.system() == 'Windows':
assert ipv6.int_to_str(0xFFFF00000000) == '::ffff:0:0'
else:
assert ipv6.int_to_str(0xFFFF00000000) == '::ffff:0.0.0.0'

@TinfoilSubmarine
Copy link
Author

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
Copy link
Contributor

jstasiak commented May 7, 2024

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
Copy link
Contributor

What does this return on your machine @TinfoilSubmarine?

python -c 'import platform; print(platform.libc_ver())'

@TinfoilSubmarine
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

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 added a commit that referenced this issue May 26, 2024
musl's inet_ntop doesn't format IPv4-compatible IPv6 addresses in any
special way and there's no dot notation in the output there.

We need to account for that.

In doctests this is achieved by changing the examples or, where not
applicable, disabling them.

In more standard test code we simply made a few tests conditional.

Resolves: #381
jstasiak added a commit that referenced this issue May 26, 2024
musl's inet_ntop doesn't format IPv4-compatible IPv6 addresses in any
special way and there's no dot notation in the output there.

We need to account for that.

In doctests this is achieved by changing the examples or, where not
applicable, disabling them.

In more standard test code we simply made a few tests conditional.

Resolves: #381
@jstasiak
Copy link
Contributor

The fix for this has been released in netaddr 1.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants