diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2017-05-09 19:22:53 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2017-05-22 17:15:09 +0000 |
commit | 6914a229a038206341ae1fea46393965a555ca9a (patch) | |
tree | 4a11cfaed46dabc827c5ee17cd976f42b5f53d49 /ext/pybind11/tests/test_stl_binders.py | |
parent | ca1d18d599dcc620bf526fb22042af95b1b60b68 (diff) | |
download | gem5-6914a229a038206341ae1fea46393965a555ca9a.tar.xz |
ext: Upgrade PyBind11 to version 2.1.1
Change-Id: I16870dec402d661295f9d013dc23e362b2b2c169
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/3225
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'ext/pybind11/tests/test_stl_binders.py')
-rw-r--r-- | ext/pybind11/tests/test_stl_binders.py | 58 |
1 files changed, 58 insertions, 0 deletions
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 |