test_issue221.py

Overview

`test_issue221.py` is a concise test module designed to validate the behavior of the `orjson` library when loading malformed JSON byte strings. Specifically, it tests that `orjson.loads()` correctly raises a `JSONDecodeError` when given invalid UTF-8 encoded JSON inputs. This ensures robustness in JSON deserialization by verifying error handling for malformed data.

This file uses the `pytest` framework to parametrize multiple test cases, each providing different invalid JSON byte sequences.


Detailed Explanation

Imports

Test Function: test_invalid

@pytest.mark.parametrize(
    "val",
    [
        b'"\xc8\x93',
        b'"\xc8',
    ],
)
def test_invalid(val):
    with pytest.raises(orjson.JSONDecodeError):
        orjson.loads(val)

Purpose

This test checks that `orjson.loads()` raises a `JSONDecodeError` when attempting to decode invalid JSON byte strings.

Parameters

Behavior

Examples of val


Implementation Details


Interaction with Other System Components


Visual Diagram

classDiagram
    class test_invalid {
        +val: bytes
        +test_invalid(val)
    }
    test_invalid : uses pytest.mark.parametrize
    test_invalid : calls orjson.loads(val)
    test_invalid : expects orjson.JSONDecodeError

Summary

This file is a targeted test module validating error handling in the `orjson` JSON deserialization library for malformed UTF-8 JSON byte strings. It uses parameterized tests to check multiple invalid inputs and asserts that the appropriate exceptions are raised. The simplicity and focus of this test make it a valuable safeguard against regressions in JSON decoding robustness within the broader project.