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

Function test_bytes_to_string

tests/test_builtin_casters.py:124–135  ·  view source on GitHub ↗

Tests the ability to pass bytes to C++ string-accepting functions. Note that this is one-way: the only way to return bytes to Python is via the pybind11::bytes class.

()

Source from the content-addressed store, hash-verified

122
123
124def test_bytes_to_string():
125 """Tests the ability to pass bytes to C++ string-accepting functions. Note that this is
126 one-way: the only way to return bytes to Python is via the pybind11::bytes class."""
127 # Issue #816
128
129 assert m.strlen(b"hi") == 2
130 assert m.string_length(b"world") == 5
131 assert m.string_length(b"a\x00b") == 3
132 assert m.strlen(b"a\x00b") == 1 # C-string limitation
133
134 # passing in a utf8 encoded string should work
135 assert m.string_length("💩".encode()) == 4
136
137
138def test_bytearray_to_string():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected