fix: improve bytes to str decoding error handling (#4294)

* (bugfix): Improve bytes to str decoding error handling

* regroup test

* Further broaden tests

* Add another decode error test

* Fix bug in tests

* Reviewer suggestions
This commit is contained in:
Aaron Gokaslan
2022-10-29 11:12:24 -04:00
committed by GitHub
parent fcb5554d9f
commit b07223fa69
3 changed files with 28 additions and 0 deletions

View File

@@ -244,6 +244,20 @@ def test_str(doc):
m.str_from_string_from_str(ucs_surrogates_str)
@pytest.mark.parametrize(
"func",
[
m.str_from_bytes_input,
m.str_from_cstr_input,
m.str_from_std_string_input,
],
)
def test_surrogate_pairs_unicode_error(func):
input_str = "\ud83d\ude4f".encode("utf-8", "surrogatepass")
with pytest.raises(UnicodeDecodeError):
func(input_str)
def test_bytes(doc):
assert m.bytes_from_char_ssize_t().decode() == "green"
assert m.bytes_from_char_size_t().decode() == "purple"