Skip to content

Commit a7e2458

Browse files
committed
copying modified test_pybind11_str_raw_str from current test_pybind11_str_raw_str branch
1 parent 1152ee1 commit a7e2458

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

tests/test_pytypes.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_pybind11_str_raw_str():
235235
# specifically to exercise pybind11::str::raw_str
236236
cvt = m.convert_to_pybind11_str
237237
assert cvt(u"Str") == u"Str"
238-
assert cvt(b"Bytes") == u"Bytes" if str is bytes else "b'Bytes'"
238+
assert cvt(b'Bytes') == u"Bytes" if str is bytes else "b'Bytes'"
239239
assert cvt(None) == u"None"
240240
assert cvt(False) == u"False"
241241
assert cvt(True) == u"True"
@@ -251,6 +251,16 @@ def test_pybind11_str_raw_str():
251251
assert cvt(set()) == u"set([])" if str is bytes else "set()"
252252
assert cvt({3, 3}) == u"set([3])" if str is bytes else "{3}"
253253

254+
valid_utf8 = u"DZ".encode("utf-8")
255+
valid_cvt = cvt(valid_utf8)
256+
assert type(valid_cvt) == bytes # Probably surprising.
257+
assert valid_cvt == b'\xc7\xb1'
258+
259+
malformed_utf8 = b'\x80'
260+
malformed_cvt = cvt(malformed_utf8)
261+
assert type(malformed_cvt) == bytes # Probably surprising.
262+
assert malformed_cvt == b'\x80'
263+
254264

255265
def test_implicit_casting():
256266
"""Tests implicit casting when assigning or appending to dicts and lists."""

0 commit comments

Comments
 (0)