domdfcoding / singledispatch-json

Custom JSON Encoder for Python utilising functools.singledispatch to support custom encoders for both Python's built-in classes and user-created classes, without as much legwork.
https://singledispatch-json.readthedocs.io/en/latest
MIT License
0 stars 3 forks source link

test_unexpected_data fails on Python 3.13 #55

Open wRAR opened 1 month ago

wRAR commented 1 month ago

3 tests fail with the same reason:

    def __test_invalid_input(data: str, msg: str, idx: int) -> None:
        with pytest.raises(sdjson.JSONDecodeError) as err:
                sdjson.loads(data)

        if PYPY:
                assert err.value.msg.startswith(msg)  # Fix for varying messages between PyPy versions
        else:
>               assert err.value.msg == msg
E     AssertionError: assert 'Illegal trai...end of object' == 'Expecting pr...double quotes'
E
E       - Expecting property name enclosed in double quotes
E       + Illegal trailing comma before end of object

Found in https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1082269 and I can confirm it locally.

mcepl commented 1 month ago

The same here on openSUSE:

[    6s] =================================== FAILURES ===================================
[    6s] ________________ test_unexpected_data[[42,]-Expecting value-4] _________________
[    6s] 
[    6s] data = '[42,]', msg = 'Expecting value', idx = 4
[    6s] 
[    6s]     @pytest.mark.parametrize(
[    6s]            "data, msg, idx",
[    6s]            [
[    6s]                    ("[,", "Unexpected ','" if PYPY else "Expecting value", 1),
[    6s]                    ('{"spam":[}', unexpected_right_brace, 9),
[    6s]                    ("[42:", unexpected_colon, 3),
[    6s]                    ('[42 "spam"', "Unexpected '\"' when decoding array" if PYPY else "Expecting ',' delimiter", 4),
[    6s]                    ("[42,]", "Unexpected ']'" if PYPY else "Expecting value", 4),
[    6s]                    ('{"spam":[42}', "Unexpected '}' when decoding array" if PYPY else "Expecting ',' delimiter", 11),
[    6s]                    ('["]', "Unterminated string starting at", 1),
[    6s]                    ('["spam":', unexpected_colon, 7),
[    6s]                    ('["spam",]', "Unexpected ']'" if PYPY else "Expecting value", 8),
[    6s]                    ("{:", property_name_string, 1),
[    6s]                    ("{,", property_name_string, 1),
[    6s]                    ("{42", property_name_string, 1),
[    6s]                    ("[{]", property_name_string, 2),
[    6s]                    ('{"spam",', missing_colon, 7),
[    6s]                    ('{"spam"}', missing_colon, 7),
[    6s]                    ('[{"spam"]', missing_colon, 8),
[    6s]                    ('{"spam":}', unexpected_right_brace, 8),
[    6s]                    ('[{"spam":]', "Unexpected ']'" if PYPY else "Expecting value", 9),
[    6s]                    (
[    6s]                            '{"spam":42 "ham"',
[    6s]                            "Unexpected '\"' when decoding object" if PYPY else "Expecting ',' delimiter",
[    6s]                            11
[    6s]                            ),
[    6s]                    ('[{"spam":42]', "Unexpected ']' when decoding object" if PYPY else "Expecting ',' delimiter", 11),
[    6s]                    ('{"spam":42,}', property_name_string, 11),
[    6s]                    ]
[    6s]            )
[    6s]     def test_unexpected_data(data: str, msg: str, idx: int):
[    6s] >      __test_invalid_input(data, msg, idx)
[    6s] 
[    6s] tests/stdlib_tests/test_fail.py:189: 
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[    6s] 
[    6s] data = '[42,]', msg = 'Expecting value', idx = 4
[    6s] 
[    6s]     def __test_invalid_input(data: str, msg: str, idx: int) -> None:
[    6s]        with pytest.raises(sdjson.JSONDecodeError) as err:
[    6s]            sdjson.loads(data)
[    6s]     
[    6s]        if PYPY:
[    6s]            assert err.value.msg.startswith(msg)  # Fix for varying messages between PyPy versions
[    6s]        else:
[    6s] >          assert err.value.msg == msg
[    6s] E     AssertionError: assert 'Illegal trai... end of array' == 'Expecting value'
[    6s] E       
[    6s] E       - Expecting value
[    6s] E       + Illegal trailing comma before end of array
[    6s] 
[    6s] tests/stdlib_tests/test_fail.py:116: AssertionError
[    6s] ______________ test_unexpected_data[["spam",]-Expecting value-8] _______________
[    6s] 
[    6s] data = '["spam",]', msg = 'Expecting value', idx = 8
[    6s] 
[    6s]     @pytest.mark.parametrize(
[    6s]            "data, msg, idx",
[    6s]            [
[    6s]                    ("[,", "Unexpected ','" if PYPY else "Expecting value", 1),
[    6s]                    ('{"spam":[}', unexpected_right_brace, 9),
[    6s]                    ("[42:", unexpected_colon, 3),
[    6s]                    ('[42 "spam"', "Unexpected '\"' when decoding array" if PYPY else "Expecting ',' delimiter", 4),
[    6s]                    ("[42,]", "Unexpected ']'" if PYPY else "Expecting value", 4),
[    6s]                    ('{"spam":[42}', "Unexpected '}' when decoding array" if PYPY else "Expecting ',' delimiter", 11),
[    6s]                    ('["]', "Unterminated string starting at", 1),
[    6s]                    ('["spam":', unexpected_colon, 7),
[    6s]                    ('["spam",]', "Unexpected ']'" if PYPY else "Expecting value", 8),
[    6s]                    ("{:", property_name_string, 1),
[    6s]                    ("{,", property_name_string, 1),
[    6s]                    ("{42", property_name_string, 1),
[    6s]                    ("[{]", property_name_string, 2),
[    6s]                    ('{"spam",', missing_colon, 7),
[    6s]                    ('{"spam"}', missing_colon, 7),
[    6s]                    ('[{"spam"]', missing_colon, 8),
[    6s]                    ('{"spam":}', unexpected_right_brace, 8),
[    6s]                    ('[{"spam":]', "Unexpected ']'" if PYPY else "Expecting value", 9),
[    6s]                    (
[    6s]                            '{"spam":42 "ham"',
[    6s]                            "Unexpected '\"' when decoding object" if PYPY else "Expecting ',' delimiter",
[    6s]                            11
[    6s]                            ),
[    6s]                    ('[{"spam":42]', "Unexpected ']' when decoding object" if PYPY else "Expecting ',' delimiter", 11),
[    6s]                    ('{"spam":42,}', property_name_string, 11),
[    6s]                    ]
[    6s]            )
[    6s]     def test_unexpected_data(data: str, msg: str, idx: int):
[    6s] >      __test_invalid_input(data, msg, idx)
[    6s] 
[    6s] tests/stdlib_tests/test_fail.py:189: 
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[    6s] 
[    6s] data = '["spam",]', msg = 'Expecting value', idx = 8
[    6s] 
[    6s]     def __test_invalid_input(data: str, msg: str, idx: int) -> None:
[    6s]        with pytest.raises(sdjson.JSONDecodeError) as err:
[    6s]            sdjson.loads(data)
[    6s]     
[    6s]        if PYPY:
[    6s]            assert err.value.msg.startswith(msg)  # Fix for varying messages between PyPy versions
[    6s]        else:
[    6s] >          assert err.value.msg == msg
[    6s] E     AssertionError: assert 'Illegal trai... end of array' == 'Expecting value'
[    6s] E       
[    6s] E       - Expecting value
[    6s] E       + Illegal trailing comma before end of array
[    6s] 
[    6s] tests/stdlib_tests/test_fail.py:116: AssertionError
[    6s] _ test_unexpected_data[{"spam":42,}-Expecting property name enclosed in double quotes-11] _
[    6s] 
[    6s] data = '{"spam":42,}', msg = 'Expecting property name enclosed in double quotes'
[    6s] idx = 11
[    6s] 
[    6s]     @pytest.mark.parametrize(
[    6s]            "data, msg, idx",
[    6s]            [
[    6s]                    ("[,", "Unexpected ','" if PYPY else "Expecting value", 1),
[    6s]                    ('{"spam":[}', unexpected_right_brace, 9),
[    6s]                    ("[42:", unexpected_colon, 3),
[    6s]                    ('[42 "spam"', "Unexpected '\"' when decoding array" if PYPY else "Expecting ',' delimiter", 4),
[    6s]                    ("[42,]", "Unexpected ']'" if PYPY else "Expecting value", 4),
[    6s]                    ('{"spam":[42}', "Unexpected '}' when decoding array" if PYPY else "Expecting ',' delimiter", 11),
[    6s]                    ('["]', "Unterminated string starting at", 1),
[    6s]                    ('["spam":', unexpected_colon, 7),
[    6s]                    ('["spam",]', "Unexpected ']'" if PYPY else "Expecting value", 8),
[    6s]                    ("{:", property_name_string, 1),
[    6s]                    ("{,", property_name_string, 1),
[    6s]                    ("{42", property_name_string, 1),
[    6s]                    ("[{]", property_name_string, 2),
[    6s]                    ('{"spam",', missing_colon, 7),
[    6s]                    ('{"spam"}', missing_colon, 7),
[    6s]                    ('[{"spam"]', missing_colon, 8),
[    6s]                    ('{"spam":}', unexpected_right_brace, 8),
[    6s]                    ('[{"spam":]', "Unexpected ']'" if PYPY else "Expecting value", 9),
[    6s]                    (
[    6s]                            '{"spam":42 "ham"',
[    6s]                            "Unexpected '\"' when decoding object" if PYPY else "Expecting ',' delimiter",
[    6s]                            11
[    6s]                            ),
[    6s]                    ('[{"spam":42]', "Unexpected ']' when decoding object" if PYPY else "Expecting ',' delimiter", 11),
[    6s]                    ('{"spam":42,}', property_name_string, 11),
[    6s]                    ]
[    6s]            )
[    6s]     def test_unexpected_data(data: str, msg: str, idx: int):
[    6s] >      __test_invalid_input(data, msg, idx)
[    6s] 
[    6s] tests/stdlib_tests/test_fail.py:189: 
[    6s] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[    6s] 
[    6s] data = '{"spam":42,}', msg = 'Expecting property name enclosed in double quotes'
[    6s] idx = 11
[    6s] 
[    6s]     def __test_invalid_input(data: str, msg: str, idx: int) -> None:
[    6s]        with pytest.raises(sdjson.JSONDecodeError) as err:
[    6s]            sdjson.loads(data)
[    6s]     
[    6s]        if PYPY:
[    6s]            assert err.value.msg.startswith(msg)  # Fix for varying messages between PyPy versions
[    6s]        else:
[    6s] >          assert err.value.msg == msg
[    6s] E     AssertionError: assert 'Illegal trai...end of object' == 'Expecting pr...double quotes'
[    6s] E       
[    6s] E       - Expecting property name enclosed in double quotes
[    6s] E       + Illegal trailing comma before end of object
[    6s] 
[    6s] tests/stdlib_tests/test_fail.py:116: AssertionError
[    6s] ============================= slowest 25 durations =============================
[    6s] 0.06s call     tests/stdlib_tests/test_unicode.py::test_unicode_decode
[    6s] 0.06s call     tests/stdlib_tests/test_recursion.py::test_highly_nested_objects_encoding
[    6s] 
[    6s] (23 durations < 0.005s hidden.  Use -vv to show these durations.)
[    6s] =========================== short test summary info ============================
[    6s] FAILED tests/stdlib_tests/test_fail.py::test_unexpected_data[[42,]-Expecting value-4] - AssertionError: assert 'Illegal trai... end of array' == 'Expecting value'
[    6s] FAILED tests/stdlib_tests/test_fail.py::test_unexpected_data[["spam",]-Expecting value-8] - AssertionError: assert 'Illegal trai... end of array' == 'Expecting value'
[    6s] FAILED tests/stdlib_tests/test_fail.py::test_unexpected_data[{"spam":42,}-Expecting property name enclosed in double quotes-11] - AssertionError: assert 'Illegal trai...end of object' == 'Expecting pr...do...
[    6s] =================== 3 failed, 148 passed, 4 xfailed in 0.40s ===================

Complete build log with the record of all packages used and steps taken to reproduce.