From 6914a229a038206341ae1fea46393965a555ca9a Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Tue, 9 May 2017 19:22:53 +0100 Subject: ext: Upgrade PyBind11 to version 2.1.1 Change-Id: I16870dec402d661295f9d013dc23e362b2b2c169 Signed-off-by: Andreas Sandberg Reviewed-by: Curtis Dunham Reviewed-on: https://gem5-review.googlesource.com/3225 Reviewed-by: Jason Lowe-Power --- ext/pybind11/tests/test_stl_binders.py | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'ext/pybind11/tests/test_stl_binders.py') diff --git a/ext/pybind11/tests/test_stl_binders.py b/ext/pybind11/tests/test_stl_binders.py index c9bcc7935..0edf9e26e 100644 --- a/ext/pybind11/tests/test_stl_binders.py +++ b/ext/pybind11/tests/test_stl_binders.py @@ -1,3 +1,10 @@ +import pytest +import sys + +with pytest.suppress(ImportError): + import numpy as np + + def test_vector_int(): from pybind11_tests import VectorInt @@ -26,6 +33,57 @@ def test_vector_int(): assert v_int2 == VectorInt([0, 99, 2, 3]) +@pytest.unsupported_on_pypy +def test_vector_buffer(): + from pybind11_tests import VectorUChar, create_undeclstruct + b = bytearray([1, 2, 3, 4]) + v = VectorUChar(b) + assert v[1] == 2 + v[2] = 5 + m = memoryview(v) # We expose the buffer interface + if sys.version_info.major > 2: + assert m[2] == 5 + m[2] = 6 + else: + assert m[2] == '\x05' + m[2] = '\x06' + assert v[2] == 6 + + with pytest.raises(RuntimeError): + create_undeclstruct() # Undeclared struct contents, no buffer interface + + +@pytest.requires_numpy +def test_vector_buffer_numpy(): + from pybind11_tests import VectorInt, VectorStruct, get_vectorstruct + + a = np.array([1, 2, 3, 4], dtype=np.int32) + with pytest.raises(TypeError): + VectorInt(a) + + a = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]], dtype=np.uintc) + v = VectorInt(a[0, :]) + assert len(v) == 4 + assert v[2] == 3 + m = np.asarray(v) + m[2] = 5 + assert v[2] == 5 + + v = VectorInt(a[:, 1]) + assert len(v) == 3 + assert v[2] == 10 + + v = get_vectorstruct() + assert v[0].x == 5 + m = np.asarray(v) + m[1]['x'] = 99 + assert v[1].x == 99 + + v = VectorStruct(np.zeros(3, dtype=np.dtype([('w', 'bool'), ('x', 'I'), + ('y', 'float64'), ('z', 'bool')], align=True))) + assert len(v) == 3 + + def test_vector_custom(): from pybind11_tests import El, VectorEl, VectorVectorEl -- cgit v1.2.3