MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_unicode_conversion

Function test_unicode_conversion

tests/test_builtin_casters.py:16–48  ·  view source on GitHub ↗

Tests unicode conversion and error reporting.

()

Source from the content-addressed store, hash-verified

14
15
16def test_unicode_conversion():
17 """Tests unicode conversion and error reporting."""
18 assert m.good_utf8_string() == "Say utf8‽ 🎂 𝐀"
19 assert m.good_utf16_string() == "b‽🎂𝐀z"
20 assert m.good_utf32_string() == "a𝐀🎂‽z"
21 assert m.good_wchar_string() == "a⸘𝐀z"
22 if hasattr(m, "has_u8string"):
23 assert m.good_utf8_u8string() == "Say utf8‽ 🎂 𝐀"
24
25 with pytest.raises(UnicodeDecodeError):
26 m.bad_utf8_string()
27
28 with pytest.raises(UnicodeDecodeError):
29 m.bad_utf16_string()
30
31 # These are provided only if they actually fail (they don't when 32-bit)
32 if hasattr(m, "bad_utf32_string"):
33 with pytest.raises(UnicodeDecodeError):
34 m.bad_utf32_string()
35 if hasattr(m, "bad_wchar_string"):
36 with pytest.raises(UnicodeDecodeError):
37 m.bad_wchar_string()
38 if hasattr(m, "has_u8string"):
39 with pytest.raises(UnicodeDecodeError):
40 m.bad_utf8_u8string()
41
42 assert m.u8_Z() == "Z"
43 assert m.u8_eacute() == "é"
44 assert m.u16_ibang() == "‽"
45 assert m.u32_mathbfA() == "𝐀"
46 assert m.wchar_heart() == "♥"
47 if hasattr(m, "has_u8string"):
48 assert m.u8_char8_Z() == "Z"
49
50
51def test_single_char_arguments():

Callers

nothing calls this directly

Calls 1

hasattrFunction · 0.85

Tested by

no test coverage detected