"""test_encode_decode_errors.py""" from __future__ import annotations import pytest from encode_decode_errors import decode_with, truncated_last_byte, utf8_bytes def test_utf8_length() -> None: assert utf8_bytes() == b"\xe4\xb8\xad\xe6\x96\x87" assert len(utf8_bytes()) == 6 def test_strict_raises_and_replace_recovers() -> None: with pytest.raises(UnicodeDecodeError, match="unexpected end of data"): truncated_last_byte().decode("utf-8") assert decode_with("replace") == "中\ufffd" assert decode_with("ignore") == "中"