Add pybind11::bytearray (#2799)

* Add initial implementation

* Add few more methods

* Add tests

* Fix a typo

* Use std::string constructor which takes size

* Fix implicit sign conversion error

* Add size method and test

* Remove implicit conversion

* Fix bytearray constructors and operator std::string()

* Make implicit bytearray constructor explicit

* Rerun tests

* Add null check

* Rerun tests

* Rerun tests - 2

* Remove NULL check
This commit is contained in:
Vikram Pal
2021-02-14 20:21:13 +05:30
committed by GitHub
parent cbae6d55c2
commit 417067eeb8
3 changed files with 42 additions and 1 deletions

View File

@@ -143,6 +143,11 @@ def test_bytes(doc):
)
def test_bytearray(doc):
assert m.bytearray_from_string().decode() == "foo"
assert m.bytearray_size() == len("foo")
def test_capsule(capture):
pytest.gc_collect()
with capture:
@@ -223,7 +228,7 @@ def test_accessors():
def test_constructors():
"""C++ default and converting constructors are equivalent to type calls in Python"""
types = [bytes, str, bool, int, float, tuple, list, dict, set]
types = [bytes, bytearray, str, bool, int, float, tuple, list, dict, set]
expected = {t.__name__: t() for t in types}
if env.PY2:
# Note that bytes.__name__ == 'str' in Python 2.
@@ -234,6 +239,7 @@ def test_constructors():
data = {
bytes: b"41", # Currently no supported or working conversions.
bytearray: bytearray(b"41"),
str: 42,
bool: "Not empty",
int: "42",