Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 802195 - dev-python/httpx-0.18.1 - fails test_json_without_specified_encoding_decode_error, test_json_without_specified_encoding_value_error
Summary: dev-python/httpx-0.18.1 - fails test_json_without_specified_encoding_decode_e...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: PPC64 Linux
: Normal normal (vote)
Assignee: Python Gentoo Team
URL:
Whiteboard:
Keywords: TESTFAILURE
Depends on:
Blocks:
 
Reported: 2021-07-14 20:33 UTC by ernsteiswuerfel
Modified: 2021-08-05 15:50 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build.log (0.18.1) (httpx-0.18.1:20210714-201500.log,79.77 KB, text/plain)
2021-07-14 20:33 UTC, ernsteiswuerfel
Details
emerge --info (file_802195.txt,5.78 KB, text/plain)
2021-07-14 20:34 UTC, ernsteiswuerfel
Details
build.log (0.18.2) (httpx-0.18.2:20210714-202717.log,6.81 KB, text/plain)
2021-07-14 20:35 UTC, ernsteiswuerfel
Details
build.log (0.18.2) (httpx-0.18.2:20210731-210844.log,73.47 KB, text/plain)
2021-07-31 21:13 UTC, ernsteiswuerfel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ernsteiswuerfel archtester 2021-07-14 20:33:51 UTC
Created attachment 723892 [details]
build.log (0.18.1)

[...]
=============================================== FAILURES ===============================================
__________________________ test_json_without_specified_encoding_decode_error ___________________________

    def test_json_without_specified_encoding_decode_error():
        data = {"greeting": "hello", "recipient": "world"}
        content = json.dumps(data).encode("utf-32-be")
        headers = {"Content-Type": "application/json"}
        # force incorrect guess from `guess_json_utf` to trigger error
        with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):
            response = httpx.Response(
                200,
                content=content,
                headers=headers,
            )
            with pytest.raises(json.decoder.JSONDecodeError):
>               response.json()
E               Failed: DID NOT RAISE <class 'json.decoder.JSONDecodeError'>

content    = (b'\x00\x00\x00{\x00\x00\x00"\x00\x00\x00g\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00e\x00\x00\x00t\x00\x00\x00i\x00\x00\x00n\x00\x00\x00g'
 b'\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 \x00\x00\x00"\x00\x00\x00h'
 b'\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00"'
 b'\x00\x00\x00,\x00\x00\x00 \x00\x00\x00"\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00c\x00\x00\x00i\x00\x00\x00p\x00\x00\x00i\x00\x00\x00e'
 b'\x00\x00\x00n\x00\x00\x00t\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 '
 b'\x00\x00\x00"\x00\x00\x00w\x00\x00\x00o\x00\x00\x00r\x00\x00\x00l'
 b'\x00\x00\x00d\x00\x00\x00"\x00\x00\x00}')
data       = {'greeting': 'hello', 'recipient': 'world'}
headers    = {'Content-Type': 'application/json'}
response   = <Response [200 OK]>

tests/models/test_responses.py:748: Failed
___________________________ test_json_without_specified_encoding_value_error ___________________________

    def test_json_without_specified_encoding_value_error():
        data = {"greeting": "hello", "recipient": "world"}
        content = json.dumps(data).encode("utf-32-be")
        headers = {"Content-Type": "application/json"}
        # force incorrect guess from `guess_json_utf` to trigger error
        with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):
            response = httpx.Response(200, content=content, headers=headers)
            with pytest.raises(json.decoder.JSONDecodeError):
>               response.json()
E               Failed: DID NOT RAISE <class 'json.decoder.JSONDecodeError'>

content    = (b'\x00\x00\x00{\x00\x00\x00"\x00\x00\x00g\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00e\x00\x00\x00t\x00\x00\x00i\x00\x00\x00n\x00\x00\x00g'
 b'\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 \x00\x00\x00"\x00\x00\x00h'
 b'\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00"'
 b'\x00\x00\x00,\x00\x00\x00 \x00\x00\x00"\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00c\x00\x00\x00i\x00\x00\x00p\x00\x00\x00i\x00\x00\x00e'
 b'\x00\x00\x00n\x00\x00\x00t\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 '
 b'\x00\x00\x00"\x00\x00\x00w\x00\x00\x00o\x00\x00\x00r\x00\x00\x00l'
 b'\x00\x00\x00d\x00\x00\x00"\x00\x00\x00}')
data       = {'greeting': 'hello', 'recipient': 'world'}
headers    = {'Content-Type': 'application/json'}
response   = <Response [200 OK]>

tests/models/test_responses.py:759: Failed
[...]
======================================= short test summary info ========================================
SKIPPED [46] ../../../../../../../usr/lib/python3.9/site-packages/_pytest/python.py:173: async def function and no async plugin installed (see warnings)
FAILED tests/models/test_responses.py::test_json_without_specified_encoding_decode_error - Failed: DI...
FAILED tests/models/test_responses.py::test_json_without_specified_encoding_value_error - Failed: DID...
================ 2 failed, 594 passed, 46 skipped, 2 deselected, 52 warnings in 14.08s =================
 * ERROR: dev-python/httpx-0.18.1::gentoo failed (test phase):
 *   pytest failed with python3.9
Comment 1 ernsteiswuerfel archtester 2021-07-14 20:34:27 UTC
Created attachment 723895 [details]
emerge --info
Comment 2 ernsteiswuerfel archtester 2021-07-14 20:35:38 UTC
Created attachment 723898 [details]
build.log (0.18.2)

0.18.2 fails to run the testsuite at all:

[...]
>>> Test phase: dev-python/httpx-0.18.2
 * python3_9: running distutils-r1_run_phase python_test
python3.9 -m pytest -vv -ra -l -Wdefault --deselect tests/client/test_proxies.py::test_async_proxy_close --deselect tests/client/test_proxies.py::test_sync_proxy_close
ImportError while loading conftest '/var/tmp/portage/dev-python/httpx-0.18.2/work/httpx-0.18.2/tests/conftest.py'.
tests/conftest.py:17: in <module>
    from typing_extensions import Literal
E   ModuleNotFoundError: No module named 'typing_extensions'
 * ERROR: dev-python/httpx-0.18.2::gentoo failed (test phase):
 *   pytest failed with python3.9
Comment 3 Larry the Git Cow gentoo-dev 2021-07-26 07:03:17 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=77abbe5810741f9fce7130d715483b2c9db3b332

commit 77abbe5810741f9fce7130d715483b2c9db3b332
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2021-07-26 07:02:50 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2021-07-26 07:03:14 +0000

    dev-python/httpx: Add test-dep on typing-extensions
    
    Bug: https://bugs.gentoo.org/802195
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-python/httpx/httpx-0.18.1.ebuild | 1 +
 dev-python/httpx/httpx-0.18.2.ebuild | 1 +
 2 files changed, 2 insertions(+)
Comment 4 ernsteiswuerfel archtester 2021-07-31 21:13:09 UTC
Created attachment 728916 [details]
build.log (0.18.2)

The 2 tests still fail but with different output now.

[...]
__________________________ test_json_without_specified_encoding_decode_error ___________________________

    def test_json_without_specified_encoding_decode_error():
        data = {"greeting": "hello", "recipient": "world"}
        content = json.dumps(data).encode("utf-32-be")
        headers = {"Content-Type": "application/json"}
        # force incorrect guess from `guess_json_utf` to trigger error
        with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):
            response = httpx.Response(
                200,
                content=content,
                headers=headers,
            )
            with pytest.raises(json.decoder.JSONDecodeError):
>               response.json()
E               Failed: DID NOT RAISE <class 'json.decoder.JSONDecodeError'>

content    = (b'\x00\x00\x00{\x00\x00\x00"\x00\x00\x00g\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00e\x00\x00\x00t\x00\x00\x00i\x00\x00\x00n\x00\x00\x00g'
 b'\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 \x00\x00\x00"\x00\x00\x00h'
 b'\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00"'
 b'\x00\x00\x00,\x00\x00\x00 \x00\x00\x00"\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00c\x00\x00\x00i\x00\x00\x00p\x00\x00\x00i\x00\x00\x00e'
 b'\x00\x00\x00n\x00\x00\x00t\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 '
 b'\x00\x00\x00"\x00\x00\x00w\x00\x00\x00o\x00\x00\x00r\x00\x00\x00l'
 b'\x00\x00\x00d\x00\x00\x00"\x00\x00\x00}')
data       = {'greeting': 'hello', 'recipient': 'world'}
headers    = {'Content-Type': 'application/json'}
response   = <Response [200 OK]>

tests/models/test_responses.py:748: Failed
___________________________ test_json_without_specified_encoding_value_error ___________________________

    def test_json_without_specified_encoding_value_error():
        data = {"greeting": "hello", "recipient": "world"}
        content = json.dumps(data).encode("utf-32-be")
        headers = {"Content-Type": "application/json"}
        # force incorrect guess from `guess_json_utf` to trigger error
        with mock.patch("httpx._models.guess_json_utf", return_value="utf-32"):
            response = httpx.Response(200, content=content, headers=headers)
            with pytest.raises(json.decoder.JSONDecodeError):
>               response.json()
E               Failed: DID NOT RAISE <class 'json.decoder.JSONDecodeError'>

content    = (b'\x00\x00\x00{\x00\x00\x00"\x00\x00\x00g\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00e\x00\x00\x00t\x00\x00\x00i\x00\x00\x00n\x00\x00\x00g'
 b'\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 \x00\x00\x00"\x00\x00\x00h'
 b'\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00"'
 b'\x00\x00\x00,\x00\x00\x00 \x00\x00\x00"\x00\x00\x00r\x00\x00\x00e'
 b'\x00\x00\x00c\x00\x00\x00i\x00\x00\x00p\x00\x00\x00i\x00\x00\x00e'
 b'\x00\x00\x00n\x00\x00\x00t\x00\x00\x00"\x00\x00\x00:\x00\x00\x00 '
 b'\x00\x00\x00"\x00\x00\x00w\x00\x00\x00o\x00\x00\x00r\x00\x00\x00l'
 b'\x00\x00\x00d\x00\x00\x00"\x00\x00\x00}')
data       = {'greeting': 'hello', 'recipient': 'world'}
headers    = {'Content-Type': 'application/json'}
response   = <Response [200 OK]>

tests/models/test_responses.py:759: Failed
=========================================== warnings summary ===========================================
tests/test_timeouts.py::test_write_timeout[asyncio]
  /usr/lib/python3.9/asyncio/base_events.py:424: ResourceWarning: unclosed <socket.socket fd=22, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 52400), raddr=('127.0.0.1', 8000)>
    return futures.Future(loop=self)

tests/test_timeouts.py::test_write_timeout[asyncio]
  /usr/lib/python3.9/asyncio/selector_events.py:704: ResourceWarning: unclosed transport <_SelectorSocketTransport fd=22>
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)

tests/client/test_async_client.py::test_100_continue[asyncio]
  /usr/lib/python3.9/asyncio/selector_events.py:704: ResourceWarning: unclosed transport <_SelectorSocketTransport fd=24>
    _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)

-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================= short test summary info ========================================
FAILED tests/models/test_responses.py::test_json_without_specified_encoding_decode_error - Failed: DI...
FAILED tests/models/test_responses.py::test_json_without_specified_encoding_value_error - Failed: DID...
======================= 2 failed, 595 passed, 2 deselected, 3 warnings in 14.19s =======================
Comment 5 Rolf Eike Beer archtester 2021-08-05 09:49:50 UTC
Also in 0.18.2 on sparc.
Comment 6 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2021-08-05 15:29:44 UTC
As Rolf correctly suggested, this seems to be an endianness issue.  To confirm, I have run tests on our ppc64 and ppc64le hosts, and the former failed while the latter passed.

I'm going to try fixing it.
Comment 7 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2021-08-05 15:31:27 UTC
Actually, it's not that hard:

    content = json.dumps(data).encode("utf-32-be")

They force BE assuming that the host is LE and therefore BE will be incorrect...
Comment 8 Larry the Git Cow gentoo-dev 2021-08-05 15:50:27 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=aa113fa2e04b2036f6d2b73c3a2355673e5c27aa

commit aa113fa2e04b2036f6d2b73c3a2355673e5c27aa
Author:     Michał Górny <mgorny@gentoo.org>
AuthorDate: 2021-08-05 15:44:53 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2021-08-05 15:50:24 +0000

    dev-python/httpx: Fix tests on big endian platforms
    
    Closes: https://bugs.gentoo.org/802195
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 .../httpx/files/httpx-0.18.2-big-endian.patch      | 40 ++++++++++++++++++++++
 dev-python/httpx/httpx-0.18.2.ebuild               |  5 +++
 2 files changed, 45 insertions(+)